
				********************************************************************
				* 		Experimental Evidence on Spillovers from an   			   *
				*				Agriculture-Nutrition Program                  	   *
				*					Data Analysis								   *	
				*																   *
				* Written: Lilia Bliznashka, January 2015 				       	   *
				* Revised: Lilia Bliznashka, April 2016 				       	   *
				* Revised: Lilia Bliznashka, September 2018				       	   *
				* Revised: Lilia Bliznashka, January 2019 				       	   *
				* Ag production section code written by Lieven Huybregts		   *
				* STATA Version 14											  	   *
				********************************************************************

version 13				
clear all
cap log close
set matsize 800
set seed 1957469

ssc install mmerge
ssc install zscore06

cd "C:\Users\tjb0217\Box Sync\Miscellaneous\Test\EHB Revision - Public"

*** define globals ***
	di "`c(pwd)'"

	global dir=subinstr(`"`c(pwd)'"',"do","",.)
	di "$dir"
	global data2010 `"$dir\data\Round 1 2010"'
	global data2012 `"$dir\data\Round 2 2012"'
	global data2013 `"$dir\data\Round 3 2013"'
	global datam `"$dir\data\Merged"'
	global do `"$dir\do"'
	di "$do"
	global out `"$dir\out"'

*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
* 		Balancing Test of Initial Cohort of Household and Child Characteristics	- BY TREATMENT GROUP		*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
	
	*********************************
	*** HOUSEHOLD CHARACTERISTICS ***
	*********************************

	* load household characteristics *
		do "$do\hh characteristics_v1"
		
		sort hhid  
		order hhid treatment hh_size nchildren wives femalehead men_asset_value women_asset_value floor roof anyeduc_head anyeduc_mother 
		
	* merge household attrition indicators and weights *
		merge 1:1 hhid using "$dir\data\hh_attrition.dta", nogen keep (mas mat) keepusing (status village_code newHH attrition)
		merge 1:1 hhid using "$dir\data\hh_attrition_weights.dta", nogen keep(mat mas) keepusing(weight)
		sort hhid
				
	* recode baseline-endline attrition status to a binary variable *
		recode status (1=0) (2=1) 
		lab var status "HH attrited?" 
		lab val status yesno
		tab status, m

	* create treatment indicators *
		g OWL=1 if treatment==1
		g HC=1 if treatment==2
		replace OWL=0 if treatment==0 | treatment==2
		replace HC=0 if treatment==0 | treatment==1
		lab val OWL HC yesno
		tab1 OWL HC, m
		
	* define indicators for balancing test *
		local depvars hh_size nchildren wives femalehead men_asset_value women_asset_value floor roof anyeduc_head anyeduc_mother
		sort hhid
		
	* create table with descriptive statistics for household characteristics *
		* entire sample *
		foreach var in `depvars' {
			
				sum `var' if status==0
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
				
				matrix `var'= N`var'\ m`var'\ sd`var'
				matrix rownames `var'=`var'
				
		}
			
		matrix sample=hh_size\nchildren\wives\femalehead\men_asset_value\women_asset_value\floor\roof\anyeduc_head\anyeduc_mother

		frmttable using "$out\Balance_tests_hh", replace sdec(4, 4, 4) statmat(sample)  ///
						title("Balancing Test of Initial Cohort of Household and Child Characteristics: Household characteristics of entire sample") ///
						coljust(l;c) ctitles("" , Sample) 
		
		* control, owl and hc groups *
		foreach var in `depvars' {
			
			forvalues n=0/2 {
				sum `var' if treatment==`n' & status==0
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
			}
				
				matrix `var'= N`var'0,N`var'1,N`var'2\ m`var'0, m`var'1, m`var'2\ sd`var'0, sd`var'1, sd`var'2
				matrix rownames `var'=`var'
						
		}
		
		matrix groups=hh_size\nchildren\wives\femalehead\men_asset_value\women_asset_value\floor\roof\anyeduc_head\anyeduc_mother

		frmttable using "$out\Balance_tests_hh_group", replace sdec(4, 4, 4) statmat(groups)  ///
						title("Balancing Test of Initial Cohort of Household and Child Characteristics: Household characteristics of treatment groups") ///
						coljust(l;c)  ctitles("" , Control, OWL, HC) 
			
	* test for differences in means *		
		eststo clear
		
		foreach i in `depvars' {
			reg `i' OWL HC if status==0, vce(cluster village_code),  
			testparm OWL HC 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	

		xml_tab  *_1, save($out\balance_tests.xls) stats(N pvalue_all) title(OWL vs. HC) sd2 replace sheet(hh) format(SCLR3 NCLR3) keep(OWL HC)

		
	********************************
	*** CHILDREN CHARACTERISTICS ***
	********************************

	* load children's characteristics_v1 *
		do "$do/children's characteristics_v1"
		
		sort hhid idp_child
		order hhid idp_child treatment ch_sex r1_ch_agemo r1_s24_q9 r1_anemic r1_anemic_severe r1_ch_haz06 r1_stunted r1_ch_waz06 r1_underweight r1_ch_whz06 r1_wasting
		drop idp_mother- diff_wasting
	 	 
	* merge child's attrition status and weights *
		rename idp_child idp 
		merge m:1 hhid idp using "$dir\data\child_attrition.dta", nogen keep (mat) keepusing (status attrition newHH)
		merge m:1 hhid idp using "$dir\data\child_attrition_weights.dta", nogen keep(mat) keepusing(weight village_code)
		sort hhid
		
	* recode baseline-endline attrition status to a binary variable *		
		recode status (1=0) (2=1) (3=0)
		label values status yesno
		tab status, m
		lab var status "Child attrited?" 
		sort hhid

	* keep only children 3-12 months of age at baseline *
		keep if r1_ch_agemo>=3 & r1_ch_agemo<=12

	* create treatment indicators *
		g OWL=1 if treatment==1
		g HC=1 if treatment==2
		replace OWL=0 if treatment==0 | treatment==2
		replace HC=0 if treatment==0 | treatment==1
		lab val OWL HC yesno
		tab1 OWL HC, m
		
	* define indicators for balancing test *
		local depvars ch_sex r1_ch_agemo r1_s24_q9 r1_anemic r1_anemic_severe r1_ch_haz06 r1_stunted r1_ch_waz06 r1_underweight r1_ch_whz06 r1_wasting 
			
	* create table with descriptive statistics for children's characteristics_v1 *
		* entire sample *
		foreach var in `depvars' {
			
				sum `var' 
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)

				matrix `var'= N`var'\ m`var'\ sd`var'
				matrix rownames `var'=`var'
		}
			
		matrix sample=ch_sex\r1_ch_agemo\r1_s24_q9\r1_anemic\r1_anemic_severe\r1_ch_haz06\r1_stunted\r1_ch_waz06\r1_underweight\r1_ch_whz06\r1_wasting

		frmttable using "$out\Balance_tests_children", replace sdec(4, 4, 4) statmat(sample)  ///
						title("Balancing Test of Initial Cohort of Household and Child Characteristics: children's characteristics_v1 of entire sample") coljust(l;c)  ///
						ctitles("" , Sample) 
		
		* control, owl and hc groups *
		foreach var in `depvars' {
			
			forvalues n=0/2 {
				sum `var' if treatment==`n' 
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
				}
				matrix `var'= N`var'0,N`var'1,N`var'2\ m`var'0, m`var'1, m`var'2\ sd`var'0, sd`var'1, sd`var'2
				matrix rownames `var'=`var'
				
				
		}
		matrix groups=ch_sex\r1_ch_agemo\r1_s24_q9\r1_anemic\r1_anemic_severe\r1_ch_haz06\r1_stunted\r1_ch_waz06\r1_underweight\r1_ch_whz06\r1_wasting
		
		frmttable using "$out\Balance_tests_children_group", replace sdec(4, 4, 4) statmat(groups)  ///
						title("Balancing Test of Initial Cohort of Household and Child Characteristics: children's characteristics_v1 of treatment groups") coljust(l;c)  ///
						ctitles("" , Control, OWL, HC) 
			
			
	* test for differences in means *		
		eststo clear
		
		foreach i in `depvars' {
			reg `i' OWL HC , vce(cluster village_code),  
			testparm OWL HC 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	

		xml_tab  *_1, save($out\balance_tests.xls) stats(N pvalue_all) title(OWL vs. HC) sd2 append sheet(children) format(SCLR3 NCLR3) keep(OWL HC)
		
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
*	Balancing Test of Initial Cohort of Household and Child Characteristics - POOLED TREATMENT	*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
	
	*********************************
	*** HOUSEHOLD CHARACTERISTICS ***
	*********************************

	* load household characteristics *
		do "$do/hh characteristics_v1"
		
		sort hhid  
		order hhid treatment hh_size nchildren wives femalehead men_asset_value women_asset_value floor roof anyeduc_head anyeduc_mother 
		
	* merge household attrition indicators and weights *
		merge 1:1 hhid using "$dir\data\hh_attrition.dta", nogen keep (mas mat) keepusing (status village_code newHH attrition)
		merge 1:1 hhid using "$dir\data\hh_attrition_weights.dta", nogen keep(mat mas) keepusing(weight)
		sort hhid
				
	* recode baseline-endline attrition status to a binary variable *
		recode status (1=0) (2=1) 
		lab var status "HH attrited?" 
		lab val status yesno
		tab status, m

	* create treatment indicators *
		g pool=1 if treatment==1 | treatment==2
		replace pool=0 if treatment==0 
		lab val pool yesno
		tab pool treatment, m
		
	* define indicators for balancing test *
		local depvars hh_size nchildren wives femalehead men_asset_value women_asset_value floor roof anyeduc_head anyeduc_mother
		sort hhid

		tabstat `depvars' if status==0, by(treatment) stat (N mean sd)
		
	* create table with descriptive statistics for household characteristics *		
		* control, pool groups *
		foreach var in `depvars' {
			
			forvalues n=0/1 {
				sum `var' if pool==`n' & status==0
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
			}
				
				matrix `var'= N`var'0,N`var'1\ m`var'0, m`var'1\ sd`var'0, sd`var'1
				matrix rownames `var'=`var'
						
		}
		
		matrix groups=hh_size\nchildren\wives\femalehead\men_asset_value\women_asset_value\floor\roof\anyeduc_head\anyeduc_mother

		frmttable using "$out\Balance_tests_hh_pool", replace sdec(4, 4, 4) statmat(groups)  ///
						title("Balancing Test of Initial Cohort of Household and Child Characteristics: Household characteristics of treatment groups") ///
						coljust(l;c)  ctitles("" , Control, Pool) 
			
	* test for differences in means *		
		eststo clear
		
		foreach i in `depvars' {
			reg `i' pool if status==0, vce(cluster village_code),  
			testparm pool
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	

		xml_tab  *_1, save($out\balance_tests.xls) stats(N pvalue_all) title(Pool) sd2 append sheet(hh_pool) format(SCLR3 NCLR3) keep(pool)

		
	********************************
	*** CHILDREN CHARACTERISTICS ***
	********************************

	* load children's characteristics_v1 *
		do "$do/children's characteristics_v1"
		
		sort hhid idp_child
		order hhid idp_child treatment ch_sex r1_ch_agemo r1_s24_q9 r1_anemic r1_anemic_severe r1_ch_haz06 r1_stunted r1_ch_waz06 r1_underweight r1_ch_whz06 r1_wasting
		drop idp_mother- diff_wasting
	 	 
	* merge child's attrition status and weights *
		rename idp_child idp 
		merge m:1 hhid idp using "$dir\data\child_attrition.dta", nogen keep (mat) keepusing (status attrition newHH)
		merge m:1 hhid idp using "$dir\data\child_attrition_weights.dta", nogen keep(mat) keepusing(weight village_code)
		sort hhid
		
	* recode baseline-endline attrition status to a binary variable *		
		recode status (1=0) (2=1) (3=0)
		label values status yesno
		tab status, m
		lab var status "Child attrited?" 
		sort hhid

	* keep only children 3-12 months of age at baseline *
		keep if r1_ch_agemo>=3 & r1_ch_agemo<=12

	* create treatment indicators *
		g pool=1 if treatment==1 | treatment==2
		replace pool=0 if treatment==0 
		lab val pool yesno
		tab pool treatment, m
		
	* define indicators for balancing test *
		local depvars ch_sex r1_ch_agemo r1_s24_q9 r1_anemic r1_anemic_severe r1_ch_haz06 r1_stunted r1_ch_waz06 r1_underweight r1_ch_whz06 r1_wasting 
			
	* create table with descriptive statistics for children's characteristics_v1 *
		* control, pool groups *
		foreach var in `depvars' {
			
			forvalues n=0/1 {
				sum `var' if pool==`n' 
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
				}
				matrix `var'= N`var'0,N`var'1\ m`var'0, m`var'1\ sd`var'0, sd`var'1
				matrix rownames `var'=`var'
				
				
		}
		matrix groups=ch_sex\r1_ch_agemo\r1_s24_q9\r1_anemic\r1_anemic_severe\r1_ch_haz06\r1_stunted\r1_ch_waz06\r1_underweight\r1_ch_whz06\r1_wasting
		
		frmttable using "$out\Balance_tests_children_pool", replace sdec(4, 4, 4) statmat(groups)  ///
						title("Balancing Test of Initial Cohort of Household and Child Characteristics: children's characteristics_v1 of treatment groups") coljust(l;c)  ///
						ctitles("" , Control, Pool) 
			
			
	* test for differences in means *		
		eststo clear
		
		foreach i in `depvars' {
			reg `i' pool, vce(cluster village_code),  
			testparm pool 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	

		xml_tab  *_1, save($out\balance_tests.xls) stats(N pvalue_all) title(OWL vs. HC) sd2 append sheet(children_pool) format(SCLR3 NCLR3) keep(pool)		
		
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
*	Balancing Test of New Cohort of Household and Child Characteristics	- BY TREATMENT GROUPS  *
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
	
	*********************************
	*** HOUSEHOLD CHARACTERISTICS ***
	*********************************

	* load household characteristics *
		do "$do/hh characteristics newhh_v1"
	
		sort hhid  
		order hhid treatment hh_size nchildren wives femalehead men_asset_value women_asset_value floor roof anyeduc_head anyeduc_mother 
		
	* merge household attrition indicators and weights *
		merge 1:1 hhid using "$dir\data\hh_attrition.dta", nogen keep (mas mat) keepusing (newHH village_code attrition)
		merge 1:1 hhid using "$dir\data\hh_attrition_weights.dta", nogen keep(mat mas) keepusing(weight)
		sort hhid
	
	* recode baseline-endline attrition status to a binary variable *
		tab attrition, m
		recode attrition (4=0) (5=1), gen(status) 
		lab var status "HH attrited?" 
		lab val status yesno
		tab status, m

	* create treatment indicators *
		g OWL=1 if treatment==1
		g HC=1 if treatment==2
		replace OWL=0 if treatment==0 | treatment==2
		replace HC=0 if treatment==0 | treatment==1
		lab val OWL HC yesno
		tab1 OWL HC, m
		
	* define indicators for balancing test *
		local depvars hh_size nchildren wives femalehead men_asset_value women_asset_value floor roof anyeduc_head anyeduc_mother
		sort hhid
		
	* create table with descriptive statistics for household characteristics *
		* entire sample *
		foreach var in `depvars' {
			
				sum `var' if status==0
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
				
				matrix `var'= N`var'\ m`var'\ sd`var'
				matrix rownames `var'=`var'
				
		}
			
		matrix sample=hh_size\nchildren\wives\femalehead\men_asset_value\women_asset_value\floor\roof\anyeduc_head\anyeduc_mother

		frmttable using "$out\Balance_tests_newhh", replace sdec(4, 4, 4) statmat(sample)  ///
						title("Balancing Test of New Cohort of Household and Child Characteristics: Household characteristics of entire sample") ///
						coljust(l;c) ctitles("" , Sample) 
		
		* control, owl and hc groups *
		foreach var in `depvars' {
			
			forvalues n=0/2 {
				sum `var' if treatment==`n' & status==0
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
			}
				
				matrix `var'= N`var'0,N`var'1,N`var'2\ m`var'0, m`var'1, m`var'2\ sd`var'0, sd`var'1, sd`var'2
				matrix rownames `var'=`var'
						
		}
		
		matrix groups=hh_size\nchildren\wives\femalehead\men_asset_value\women_asset_value\floor\roof\anyeduc_head\anyeduc_mother

		frmttable using "$out\Balance_tests_newhh_group", replace sdec(4, 4, 4) statmat(groups)  ///
						title("Balancing Test of New Cohort of Household and Child Characteristics: Household characteristics of treatment groups") ///
						coljust(l;c)  ctitles("" , Control, OWL, HC) 
			
	* test for differences in means *		
		eststo clear
		
		foreach i in `depvars' {
			reg `i' OWL HC if status==0, vce(cluster village_code),  
			testparm OWL HC 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	

		xml_tab  *_1, save($out\balance_tests.xls) stats(N pvalue_all) title(OWL vs. HC) sd2 append sheet(newhh) format(SCLR3 NCLR3) keep(OWL HC)

		
	********************************
	*** CHILDREN CHARACTERISTICS ***
	********************************

	* load children's characteristics_v1 *
		do "$do/children's characteristics (newhh)_v1"
		
		sort hhid idp_child
		order hhid idp_child treatment ch_sex r2_ch_agemo r2_s24_q9 r2_anemic r2_anemic_severe r2_ch_haz06 r2_stunted r2_ch_waz06 r2_underweight r2_ch_whz06 r2_wasting
		drop idp_mother- diff_wasting
	 	 
	* merge child's attrition status and weights *
		rename idp_child idp 
		merge m:1 hhid idp using "$dir\data\child_attrition.dta", nogen keep (mat) keepusing (attrition newHH)
		merge m:1 hhid idp using "$dir\data\child_attrition_weights.dta", nogen keep(mat) keepusing(weight village_code)
		sort hhid
		
	* recode baseline-endline attrition status to a binary variable *
		tab1 attrition, m
		
		recode attrition (5=0), gen(status)
		label values status yesno
		tab status, m
		lab var status "Child attrited?" 
		sort hhid

	* create treatment indicators *
		g OWL=1 if treatment==1
		g HC=1 if treatment==2
		replace OWL=0 if treatment==0 | treatment==2
		replace HC=0 if treatment==0 | treatment==1
		lab val OWL HC yesno
		tab1 OWL HC, m
		
	* define indicators for balancing test *
		local depvars ch_sex r2_ch_agemo r2_s24_q9 r2_anemic r2_anemic_severe r2_ch_haz06 r2_stunted r2_ch_waz06 r2_underweight r2_ch_whz06 r2_wasting  
			
	* create table with descriptive statistics for children's characteristics_v1 *
		* entire sample *
		foreach var in `depvars' {
			
				sum `var' 
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)

				matrix `var'= N`var'\ m`var'\ sd`var'
				matrix rownames `var'=`var'
		}
			
		matrix sample=ch_sex\r2_ch_agemo\r2_s24_q9\r2_anemic\r2_anemic_severe\r2_ch_haz06\r2_stunted\r2_ch_waz06\r2_underweight\r2_ch_whz06\r2_wasting

		frmttable using "$out\Balance_tests_children_new", replace sdec(4, 4, 4) statmat(sample)  ///
						title("Balancing Test of New Cohort of Household and Child Characteristics: children's characteristics_v1 of entire sample") coljust(l;c)  ///
						ctitles("" , Sample) 
		
		* control, owl and hc groups *
		foreach var in `depvars' {
			
			forvalues n=0/2 {
				sum `var' if treatment==`n' 
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
				}
				matrix `var'= N`var'0,N`var'1,N`var'2\ m`var'0, m`var'1, m`var'2\ sd`var'0, sd`var'1, sd`var'2
				matrix rownames `var'=`var'
				
				
		}
		matrix groups=ch_sex\r2_ch_agemo\r2_s24_q9\r2_anemic\r2_anemic_severe\r2_ch_haz06\r2_stunted\r2_ch_waz06\r2_underweight\r2_ch_whz06\r2_wasting
		
		frmttable using "$out\Balance_tests_children_new_group", replace sdec(4, 4, 4) statmat(groups)  ///
						title("Balancing Test of New Cohort of Household and Child Characteristics: children's characteristics_v1 of treatment groups") coljust(l;c)  ///
						ctitles("" , Control, OWL, HC) 
			
			
	* test for differences in means *		
		eststo clear
		
		foreach i in `depvars' {
			reg `i' OWL HC , vce(cluster village_code),  
			testparm OWL HC 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	

		xml_tab  *_1, save($out\balance_tests.xls) stats(N pvalue_all) title(OWL vs. HC) sd2 append sheet(children_new) format(SCLR3 NCLR3) keep(OWL HC)
	
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
*	Balancing Test of New Cohort of Household and Child Characteristics - POOLED TREATMENT	 *
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*	
	*********************************
	*** HOUSEHOLD CHARACTERISTICS ***
	*********************************

	* load household characteristics *
		do "$do/hh characteristics newhh_v1"
	
		sort hhid  
		order hhid treatment hh_size nchildren wives femalehead men_asset_value women_asset_value floor roof anyeduc_head anyeduc_mother 
		
	* merge household attrition indicators and weights *
		merge 1:1 hhid using "$dir\data\hh_attrition.dta", nogen keep (mas mat) keepusing (newHH village_code attrition)
		merge 1:1 hhid using "$dir\data\hh_attrition_weights.dta", nogen keep(mat mas) keepusing(weight)
		sort hhid
	
	* recode baseline-endline attrition status to a binary variable *
		tab attrition, m
		recode attrition (4=0) (5=1), gen(status) 
		lab var status "HH attrited?" 
		lab val status yesno
		tab status, m

	* create treatment indicators *
		g pool=1 if treatment==1 | treatment==2
		replace pool=0 if treatment==0 
		lab val pool yesno
		tab pool treatment, m
		
	* define indicators for balancing test *
		local depvars hh_size nchildren wives femalehead men_asset_value women_asset_value floor roof anyeduc_head anyeduc_mother
		sort hhid

		tabstat `depvars' if status==0, by(treatment) stat (N mean sd)
		
	* create table with descriptive statistics for household characteristics *		
		* control, owl and hc groups *
		foreach var in `depvars' {
			
			forvalues n=0/1 {
				sum `var' if pool==`n' & status==0
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
			}
				
				matrix `var'= N`var'0,N`var'1\ m`var'0, m`var'1\ sd`var'0, sd`var'1
				matrix rownames `var'=`var'				
		}
		
		matrix groups=hh_size\nchildren\wives\femalehead\men_asset_value\women_asset_value\floor\roof\anyeduc_head\anyeduc_mother

		frmttable using "$out\Balance_tests_newhh_pool", replace sdec(4, 4, 4) statmat(groups)  ///
						title("Balancing Test of New Cohort of Household and Child Characteristics: Household characteristics of treatment groups") ///
						coljust(l;c)  ctitles("" , Control, Pool) 
			
	* test for differences in means *		
		eststo clear
		
		foreach i in `depvars' {
			reg `i' pool if status==0, vce(cluster village_code),  
			testparm pool
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	

		xml_tab  *_1, save($out\balance_tests.xls) stats(N pvalue_all) title(OWL vs. HC) sd2 append sheet(newhh_pool) format(SCLR3 NCLR3) keep(pool)

	********************************
	*** CHILDREN CHARACTERISTICS ***
	********************************

	* load children's characteristics_v1 *
		do "$do/children's characteristics (newhh)_v1"
		
		sort hhid idp_child
		order hhid idp_child treatment ch_sex r2_ch_agemo r2_s24_q9 r2_anemic r2_anemic_severe r2_ch_haz06 r2_stunted r2_ch_waz06 r2_underweight r2_ch_whz06 r2_wasting
		drop idp_mother- diff_wasting
	 	 
	* merge child's attrition status and weights *
		rename idp_child idp 
		merge m:1 hhid idp using "$dir\data\child_attrition.dta", nogen keep (mat) keepusing (attrition newHH)
		merge m:1 hhid idp using "$dir\data\child_attrition_weights.dta", nogen keep(mat) keepusing(weight village_code)
		sort hhid
		
	* recode baseline-endline attrition status to a binary variable *
		tab1 attrition, m
		
		recode attrition (5=0), gen(status)
		label values status yesno
		tab status, m
		lab var status "Child attrited?" 
		sort hhid

	* create treatment indicators *
		g pool=1 if treatment==1 | treatment==2
		replace pool=0 if treatment==0 
		lab val pool yesno
		tab pool treatment, m
		
	* define indicators for balancing test *
		local depvars ch_sex r2_ch_agemo r2_s24_q9 r2_anemic r2_anemic_severe r2_ch_haz06 r2_stunted r2_ch_waz06 r2_underweight r2_ch_whz06 r2_wasting  
			
	* create table with descriptive statistics for children's characteristics_v1 *		
		* control, pool groups *
		foreach var in `depvars' {
			
			forvalues n=0/1 {
				sum `var' if pool==`n' 
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
				}
				matrix `var'= N`var'0,N`var'1\ m`var'0, m`var'1\ sd`var'0, sd`var'1
				matrix rownames `var'=`var'
				
				
		}
		matrix groups=ch_sex\r2_ch_agemo\r2_s24_q9\r2_anemic\r2_anemic_severe\r2_ch_haz06\r2_stunted\r2_ch_waz06\r2_underweight\r2_ch_whz06\r2_wasting
		
		frmttable using "$out\Balance_tests_children_new_pool", replace sdec(4, 4, 4) statmat(groups)  ///
						title("Balancing Test of New Cohort of Household and Child Characteristics: children's characteristics_v1 of treatment groups") coljust(l;c)  ///
						ctitles("" , Control, OWL, HC) 
			
			
	* test for differences in means *		
		eststo clear
		
		foreach i in `depvars' {
			reg `i' pool, vce(cluster village_code),  
			testparm pool
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	

		xml_tab  *_1, save($out\balance_tests.xls) stats(N pvalue_all) title(OWL vs. HC) sd2 append sheet(children_new_pool) format(SCLR3 NCLR3) keep(pool)
		
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
* 		Balancing Test of Initial Cohort compared to New Cohort 				*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
	*********************************
	*** HOUSEHOLD CHARACTERISTICS ***
	*********************************

	* load household characteristics *
		use "$do/hh_old_new", clear
		
		sort hhid  
		order hhid treatment hh_size nchildren wives femalehead men_asset_value women_asset_value floor roof anyeduc_head anyeduc_mother 
		
	* merge household attrition indicators and weights *
		merge 1:1 hhid using "$dir\data\hh_attrition.dta", nogen keep (mas mat) keepusing (status village_code newHH attrition)
		merge 1:1 hhid using "$dir\data\hh_attrition_weights.dta", nogen keep(mat mas) keepusing(weight)
		sort hhid
				
	* recode status to binary *
		recode status (1=0) (3=1) 
		lab var status "New HH?" 
		lab val status yesno
		tab status, m
		
	* define indicators for balancing test *
		local depvars hh_size nchildren wives femalehead men_asset_value women_asset_value floor roof anyeduc_head anyeduc_mother
		sort hhid
		
	* create table with descriptive statistics for household characteristics *
		foreach var in `depvars' {
			
			forvalues n=0/1 {
				sum `var' if status==`n'
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
			}
				
				matrix `var'= N`var'0,N`var'1\ m`var'0, m`var'1\ sd`var'0, sd`var'1
				matrix rownames `var'=`var'
						
		}
		
		matrix groups=hh_size\nchildren\wives\femalehead\men_asset_value\women_asset_value\floor\roof\anyeduc_head\anyeduc_mother

		frmttable using "$out\Balance_tests_oldvsnew_hh", replace sdec(4, 4, 4) statmat(groups)  ///
						title("Balancing Test of Initial Cohort compared to New Cohort of Household and Child Characteristics") ///
						coljust(l;c)  ctitles("" , Old HH, New HH) 
			
	* test for differences in means *		
		eststo clear
		
		foreach i in `depvars' {
			reg `i' status, vce(cluster village_code),  
			testparm status
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	

		xml_tab  *_1, save($out\balance_tests.xls) stats(N pvalue_all) title(OWL vs. HC) sd2 append sheet(hh_oldvsnew) format(SCLR3 NCLR3) keep(status)

		
	********************************
	*** CHILDREN CHARACTERISTICS ***
	********************************

	* load household characteristics *
		use "$do/children_old_new", clear
		
		sort hhid idp_child
		order hhid idp_child treatment ch_sex ch_agemo s24_q9 anemic anemic_severe ch_haz06 stunted ch_waz06 underweight ch_whz06 wasting
		
	* merge child's attrition status and weights *
		rename idp_child idp 
		merge m:1 hhid idp using "$dir\data\child_attrition.dta", nogen keep (mat) keepusing (attrition newHH)
		merge m:1 hhid idp using "$dir\data\child_attrition_weights.dta", nogen keep(mat) keepusing(weight village_code)
		sort hhid		
		
	* keep only children 3-12 months of age at baseline *
		keep if ch_agemo>=3 & ch_agemo<=12
		tab newHH, m
					
	* define indicators for balancing test *
		local depvars ch_sex ch_agemo s24_q9 anemic anemic_severe ch_haz06 stunted ch_waz06 underweight ch_whz06 wasting 
		sort hhid
		
	* create table with descriptive statistics for household characteristics *
		foreach var in `depvars' {
			
			forvalues n=0/1 {
				sum `var' if newHH==`n'
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
			}
				
				matrix `var'= N`var'0,N`var'1\ m`var'0, m`var'1\ sd`var'0, sd`var'1
				matrix rownames `var'=`var'
						
		}
		
		matrix groups=ch_sex\ch_agemo\s24_q9\anemic\anemic_severe\ch_haz06\stunted\ch_waz06\underweight\ch_whz06\wasting

		frmttable using "$out\Balance_tests_oldvsnew_children", replace sdec(4, 4, 4) statmat(groups)  ///
						title("Balancing Test of Initial Cohort compared to New Cohort of Household and Child Characteristics") ///
						coljust(l;c)  ctitles("" , Old HH, New HH) 
			
	* test for differences in means *		
		eststo clear
		
		foreach i in `depvars' {
			reg `i' newHH, vce(cluster village_code),  
			testparm newHH
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	

		xml_tab  *_1, save($out\balance_tests.xls) stats(N pvalue_all) title(OWL vs. HC) sd2 append sheet(children_oldvsnew) format(SCLR3 NCLR3) keep(newHH)
		
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
* 		TEST NORMALIZED DIFFERENCES	- OLD COHORT		*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
	
	*********************************
	*** HOUSEHOLD CHARACTERISTICS ***
	*********************************

	* load household characteristics *
		do "$do/hh characteristics_v1"
		
		sort hhid  
		order hhid treatment hh_size nchildren wives femalehead men_asset_value women_asset_value floor roof anyeduc_head anyeduc_mother 
		
	* merge household attrition indicators and weights *
		merge 1:1 hhid using "$dir\data\hh_attrition.dta", nogen keep (mas mat) keepusing (status village_code newHH attrition)
		merge 1:1 hhid using "$dir\data\hh_attrition_weights.dta", nogen keep(mat mas) keepusing(weight)
		sort hhid
				
	* recode baseline-endline attrition status to a binary variable *
		recode status (1=0) (2=1) 
		lab var status "HH attrited?" 
		lab val status yesno
		tab status, m

	* create treatment indicators *
		g OWL=1 if treatment==1
		g HC=1 if treatment==2
		replace OWL=0 if treatment==0 | treatment==2
		replace HC=0 if treatment==0 | treatment==1
		lab val OWL HC yesno
		tab1 OWL HC, m
		
	* define indicators for balancing test *
		local depvars hh_size nchildren men_asset_value women_asset_value 
		sort hhid
		
	* test if variables are normally distributed *
		foreach var in `depvars' {
			g `var'_trans=ln(`var') 
			swilk `var'_trans
		}	
		
		local depvars hh_size_trans nchildren_trans men_asset_value_trans women_asset_value_trans
		
	* create table with descriptive statistics for household characteristics *
		* entire sample *
		foreach var in `depvars' {
			
				sum `var' if status==0
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
				
				matrix `var'= N`var'\ m`var'\ sd`var'
				matrix rownames `var'=`var'
				
		}
			
		matrix sample=hh_size_trans\nchildren_trans\men_asset_value_trans\women_asset_value_trans

		frmttable using "$out\Balance_tests_trans_hh", replace sdec(4, 4, 4) statmat(sample)  ///
						title("Balancing Test of Initial Cohort of Household and Child Characteristics: Household characteristics of entire sample") ///
						coljust(l;c) ctitles("" , Sample) 
		
		* control, owl and hc groups *
		foreach var in `depvars' {
			
			forvalues n=0/2 {
				sum `var' if treatment==`n' & status==0
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
			}
				
				matrix `var'= N`var'0,N`var'1,N`var'2\ m`var'0, m`var'1, m`var'2\ sd`var'0, sd`var'1, sd`var'2
				matrix rownames `var'=`var'
						
		}
		
		matrix groups=hh_size_trans\nchildren_trans\men_asset_value_trans\women_asset_value_trans

		frmttable using "$out\Balance_tests_trans_hh_group", replace sdec(4, 4, 4) statmat(groups)  ///
						title("Balancing Test of Initial Cohort of Household and Child Characteristics: Household characteristics of treatment groups") ///
						coljust(l;c)  ctitles("" , Control, OWL, HC) 
			
	* test for differences in means *		
		eststo clear
		
		foreach i in `depvars' {
			reg `i' OWL HC if status==0, vce(cluster village_code),  
			testparm OWL HC 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	

		xml_tab  *_1, save($out\balance_tests.xls) stats(N pvalue_all) title(OWL vs. HC) sd2 append sheet(trans_hh) format(SCLR3 NCLR3) keep(OWL HC)

		
	********************************
	*** CHILDREN CHARACTERISTICS ***
	********************************

	* load children's characteristics_v1 *
		do "$do/children's characteristics_v1"
		
		sort hhid idp_child
		order hhid idp_child treatment ch_sex r1_ch_agemo r1_s24_q9 r1_anemic r1_anemic_severe r1_ch_haz06 r1_stunted r1_ch_waz06 r1_underweight r1_ch_whz06 r1_wasting
		drop idp_mother- diff_wasting
	 	 
	* merge child's attrition status and weights *
		rename idp_child idp 
		merge m:1 hhid idp using "$dir\data\child_attrition.dta", nogen keep (mat) keepusing (status attrition newHH)
		merge m:1 hhid idp using "$dir\data\child_attrition_weights.dta", nogen keep(mat) keepusing(weight village_code)
		sort hhid
		
	* recode baseline-endline attrition status to a binary variable *		
		recode status (1=0) (2=1) (3=0)
		label values status yesno
		tab status, m
		lab var status "Child attrited?" 
		sort hhid

	* keep only children 3-12 months of age at baseline *
		keep if r1_ch_agemo>=3 & r1_ch_agemo<=12

	* create treatment indicators *
		g OWL=1 if treatment==1
		g HC=1 if treatment==2
		replace OWL=0 if treatment==0 | treatment==2
		replace HC=0 if treatment==0 | treatment==1
		lab val OWL HC yesno
		tab1 OWL HC, m
		
	* define indicators for balancing test *
		local depvars r1_ch_agemo r1_s24_q9 r1_ch_haz06 r1_ch_waz06 r1_ch_whz06 
			
	* test if variables are normally distributed *
		foreach var in `depvars' {
			g `var'_trans=ln(`var') 
			swilk `var'_trans
		}	
		
		local depvars r1_ch_agemo_trans r1_s24_q9_trans r1_ch_haz06_trans r1_ch_waz06_trans r1_ch_whz06_trans
		
			
	* create table with descriptive statistics for children's characteristics_v1 *
		* entire sample *
		foreach var in `depvars' {
			
				sum `var' 
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)

				matrix `var'= N`var'\ m`var'\ sd`var'
				matrix rownames `var'=`var'
		}
			
		matrix sample=r1_ch_agemo_trans\r1_s24_q9_trans\r1_ch_haz06_trans\r1_ch_waz06_trans\r1_ch_whz06_trans

		frmttable using "$out\Balance_tests_trans_children", replace sdec(4, 4, 4) statmat(sample)  ///
						title("Balancing Test of Initial Cohort of Household and Child Characteristics: children's characteristics_v1 of entire sample") coljust(l;c)  ///
						ctitles("" , Sample) 
		
		* control, owl and hc groups *
		foreach var in `depvars' {
			
			forvalues n=0/2 {
				sum `var' if treatment==`n' 
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
				}
				matrix `var'= N`var'0,N`var'1,N`var'2\ m`var'0, m`var'1, m`var'2\ sd`var'0, sd`var'1, sd`var'2
				matrix rownames `var'=`var'
				
				
		}
		matrix groups=r1_ch_agemo_trans\r1_s24_q9_trans\r1_ch_haz06_trans\r1_ch_waz06_trans\r1_ch_whz06_trans
		
		frmttable using "$out\Balance_tests_trans_children_group", replace sdec(4, 4, 4) statmat(groups)  ///
						title("Balancing Test of Initial Cohort of Household and Child Characteristics: children's characteristics_v1 of treatment groups") coljust(l;c)  ///
						ctitles("" , Control, OWL, HC) 
			
			
	* test for differences in means *		
		eststo clear
		
		foreach i in `depvars' {
			reg `i' OWL HC , vce(cluster village_code),  
			testparm OWL HC 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	

		xml_tab  *_1, save($out\balance_tests.xls) stats(N pvalue_all) title(OWL vs. HC) sd2 append sheet(trans_children) format(SCLR3 NCLR3) keep(OWL HC)
		
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
*	TEST NORMALIZED DIFFERENCES	- OLD COHORT POOLED TREATMENT	*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
	
	*********************************
	*** HOUSEHOLD CHARACTERISTICS ***
	*********************************

	* load household characteristics *
		do "$do/hh characteristics_v1"
		
		sort hhid  
		order hhid treatment hh_size nchildren wives femalehead men_asset_value women_asset_value floor roof anyeduc_head anyeduc_mother 
		
	* merge household attrition indicators and weights *
		merge 1:1 hhid using "$dir\data\hh_attrition.dta", nogen keep (mas mat) keepusing (status village_code newHH attrition)
		merge 1:1 hhid using "$dir\data\hh_attrition_weights.dta", nogen keep(mat mas) keepusing(weight)
		sort hhid
				
	* recode baseline-endline attrition status to a binary variable *
		recode status (1=0) (2=1) 
		lab var status "HH attrited?" 
		lab val status yesno
		tab status, m

	* create treatment indicators *
		g pool=1 if treatment==1 | treatment==2
		replace pool=0 if treatment==0 
		lab val pool yesno
		tab pool treatment, m
		
	* define indicators for balancing test *
		local depvars hh_size nchildren men_asset_value women_asset_value 
		sort hhid

	* test if variables are normally distributed *
		foreach var in `depvars' {
			g `var'_trans=ln(`var') 
			swilk `var'_trans
		}	
		
		local depvars hh_size_trans nchildren_trans men_asset_value_trans women_asset_value_trans
		
	* create table with descriptive statistics for household characteristics *		
		* control, pool groups *
		foreach var in `depvars' {
			
			forvalues n=0/1 {
				sum `var' if pool==`n' & status==0
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
			}
				
				matrix `var'= N`var'0,N`var'1\ m`var'0, m`var'1\ sd`var'0, sd`var'1
				matrix rownames `var'=`var'
						
		}
		
		matrix groups=hh_size_trans\nchildren_trans\men_asset_value_trans\women_asset_value_trans

		frmttable using "$out\Balance_tests_trans_hh_pool", replace sdec(4, 4, 4) statmat(groups)  ///
						title("Balancing Test of Initial Cohort of Household and Child Characteristics: Household characteristics of treatment groups") ///
						coljust(l;c)  ctitles("" , Control, Pool) 
			
	* test for differences in means *		
		eststo clear
		
		foreach i in `depvars' {
			reg `i' pool if status==0, vce(cluster village_code),  
			testparm pool
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	

		xml_tab  *_1, save($out\balance_tests.xls) stats(N pvalue_all) title(Pool) sd2 append sheet(trans_hh_pool) format(SCLR3 NCLR3) keep(pool)

		
	********************************
	*** CHILDREN CHARACTERISTICS ***
	********************************

	* load children's characteristics_v1 *
		do "$do/children's characteristics_v1"
		
		sort hhid idp_child
		order hhid idp_child treatment ch_sex r1_ch_agemo r1_s24_q9 r1_anemic r1_anemic_severe r1_ch_haz06 r1_stunted r1_ch_waz06 r1_underweight r1_ch_whz06 r1_wasting
		drop idp_mother- diff_wasting
	 	 
	* merge child's attrition status and weights *
		rename idp_child idp 
		merge m:1 hhid idp using "$dir\data\child_attrition.dta", nogen keep (mat) keepusing (status attrition newHH)
		merge m:1 hhid idp using "$dir\data\child_attrition_weights.dta", nogen keep(mat) keepusing(weight village_code)
		sort hhid
		
	* recode baseline-endline attrition status to a binary variable *		
		recode status (1=0) (2=1) (3=0)
		label values status yesno
		tab status, m
		lab var status "Child attrited?" 
		sort hhid

	* keep only children 3-12 months of age at baseline *
		keep if r1_ch_agemo>=3 & r1_ch_agemo<=12

	* create treatment indicators *
		g pool=1 if treatment==1 | treatment==2
		replace pool=0 if treatment==0 
		lab val pool yesno
		tab pool treatment, m
		
	* define indicators for balancing test *
		local depvars r1_ch_agemo r1_s24_q9 r1_ch_haz06 r1_ch_waz06 r1_ch_whz06 
		
	* test if variables are normally distributed *
		foreach var in `depvars' {
			g `var'_trans=ln(`var') 
			swilk `var'_trans
		}	
		
		local depvars r1_ch_agemo_trans r1_s24_q9_trans r1_ch_haz06_trans r1_ch_waz06_trans r1_ch_whz06_trans
		
	* create table with descriptive statistics for children's characteristics_v1 *
		* control, pool groups *
		foreach var in `depvars' {
			
			forvalues n=0/1 {
				sum `var' if pool==`n' 
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
				}
				matrix `var'= N`var'0,N`var'1\ m`var'0, m`var'1\ sd`var'0, sd`var'1
				matrix rownames `var'=`var'
				
				
		}
		matrix groups=r1_ch_agemo_trans\r1_s24_q9_trans\r1_ch_haz06_trans\r1_ch_waz06_trans\r1_ch_whz06_trans
		
		frmttable using "$out\Balance_tests_trans_children_pool", replace sdec(4, 4, 4) statmat(groups)  ///
						title("Balancing Test of Initial Cohort of Household and Child Characteristics: children's characteristics_v1 of treatment groups") coljust(l;c)  ///
						ctitles("" , Control, Pool) 
			
			
	* test for differences in means *		
		eststo clear
		
		foreach i in `depvars' {
			reg `i' pool, vce(cluster village_code),  
			testparm pool 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	

		xml_tab  *_1, save($out\balance_tests.xls) stats(N pvalue_all) title(OWL vs. HC) sd2 append sheet(trans_children_pool) format(SCLR3 NCLR3) keep(pool)		
		
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
*	TEST NORMALIZED DIFFERENCES	- NEW COHORT	*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
	*********************************
	*** HOUSEHOLD CHARACTERISTICS ***
	*********************************

	* load household characteristics *
		do "$do/hh characteristics newhh_v1"
	
		sort hhid  
		order hhid treatment hh_size nchildren wives femalehead men_asset_value women_asset_value floor roof anyeduc_head anyeduc_mother 
		
	* merge household attrition indicators and weights *
		merge 1:1 hhid using "$dir\data\hh_attrition.dta", nogen keep (mas mat) keepusing (newHH village_code attrition)
		merge 1:1 hhid using "$dir\data\hh_attrition_weights.dta", nogen keep(mat mas) keepusing(weight)
		sort hhid
	
	* recode baseline-endline attrition status to a binary variable *
		tab attrition, m
		recode attrition (4=0) (5=1), gen(status) 
		lab var status "HH attrited?" 
		lab val status yesno
		tab status, m

	* create treatment indicators *
		g OWL=1 if treatment==1
		g HC=1 if treatment==2
		replace OWL=0 if treatment==0 | treatment==2
		replace HC=0 if treatment==0 | treatment==1
		lab val OWL HC yesno
		tab1 OWL HC, m
		
	* define indicators for balancing test *
		local depvars hh_size nchildren men_asset_value women_asset_value 
		sort hhid
	
	* test if variables are normally distributed *
		foreach var in `depvars' {
			g `var'_trans=ln(`var') 
			swilk `var'_trans
		}	
		
		local depvars hh_size_trans nchildren_trans men_asset_value_trans women_asset_value_trans
	
	* create table with descriptive statistics for household characteristics *
		* entire sample *
		foreach var in `depvars' {
			
				sum `var' if status==0
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
				
				matrix `var'= N`var'\ m`var'\ sd`var'
				matrix rownames `var'=`var'
				
		}
			
		matrix sample=hh_size_trans\nchildren_trans\men_asset_value_trans\women_asset_value_trans

		frmttable using "$out\Balance_tests_trans_newhh", replace sdec(4, 4, 4) statmat(sample)  ///
						title("Balancing Test of New Cohort of Household and Child Characteristics: Household characteristics of entire sample") ///
						coljust(l;c) ctitles("" , Sample) 
		
		* control, owl and hc groups *
		foreach var in `depvars' {
			
			forvalues n=0/2 {
				sum `var' if treatment==`n' & status==0
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
			}
				
				matrix `var'= N`var'0,N`var'1,N`var'2\ m`var'0, m`var'1, m`var'2\ sd`var'0, sd`var'1, sd`var'2
				matrix rownames `var'=`var'
						
		}
		
		matrix groups=hh_size_trans\nchildren_trans\men_asset_value_trans\women_asset_value_trans

		frmttable using "$out\Balance_tests_trans_newhh_group", replace sdec(4, 4, 4) statmat(groups)  ///
						title("Balancing Test of New Cohort of Household and Child Characteristics: Household characteristics of treatment groups") ///
						coljust(l;c)  ctitles("" , Control, OWL, HC) 
			
	* test for differences in means *		
		eststo clear
		
		foreach i in `depvars' {
			reg `i' OWL HC if status==0, vce(cluster village_code),  
			testparm OWL HC 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	

		xml_tab  *_1, save($out\balance_tests.xls) stats(N pvalue_all) title(OWL vs. HC) sd2 append sheet(trans_newhh) format(SCLR3 NCLR3) keep(OWL HC)

		
	********************************
	*** CHILDREN CHARACTERISTICS ***
	********************************

	* load children's characteristics_v1 *
		do "$do/children's characteristics (newhh)_v1"
		
		sort hhid idp_child
		order hhid idp_child treatment ch_sex r2_ch_agemo r2_s24_q9 r2_anemic r2_anemic_severe r2_ch_haz06 r2_stunted r2_ch_waz06 r2_underweight r2_ch_whz06 r2_wasting
		drop idp_mother- diff_wasting
	 	 
	* merge child's attrition status and weights *
		rename idp_child idp 
		merge m:1 hhid idp using "$dir\data\child_attrition.dta", nogen keep (mat) keepusing (attrition newHH)
		merge m:1 hhid idp using "$dir\data\child_attrition_weights.dta", nogen keep(mat) keepusing(weight village_code)
		sort hhid
		
	* recode baseline-endline attrition status to a binary variable *
		tab1 attrition, m
		
		recode attrition (5=0), gen(status)
		label values status yesno
		tab status, m
		lab var status "Child attrited?" 
		sort hhid

	* create treatment indicators *
		g OWL=1 if treatment==1
		g HC=1 if treatment==2
		replace OWL=0 if treatment==0 | treatment==2
		replace HC=0 if treatment==0 | treatment==1
		lab val OWL HC yesno
		tab1 OWL HC, m
		
	* define indicators for balancing test *
		local depvars r2_ch_agemo r2_s24_q9 r2_ch_haz06 r2_ch_waz06 r2_ch_whz06 
			
	* test if variables are normally distributed *
		foreach var in `depvars' {
			g `var'_trans=ln(`var') 
			swilk `var'_trans
		}	
		
		local depvars r2_ch_agemo_trans r2_s24_q9_trans r2_ch_haz06_trans r2_ch_waz06_trans r2_ch_whz06_trans
			
	* create table with descriptive statistics for children's characteristics_v1 *
		* entire sample *
		foreach var in `depvars' {
			
				sum `var' 
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)

				matrix `var'= N`var'\ m`var'\ sd`var'
				matrix rownames `var'=`var'
		}
			
		matrix sample=r2_ch_agemo_trans\r2_s24_q9_trans\r2_ch_haz06_trans\r2_ch_waz06_trans\r2_ch_whz06_trans

		frmttable using "$out\Balance_tests_trans_children_new", replace sdec(4, 4, 4) statmat(sample)  ///
						title("Balancing Test of New Cohort of Household and Child Characteristics: children's characteristics_v1 of entire sample") coljust(l;c)  ///
						ctitles("" , Sample) 
		
		* control, owl and hc groups *
		foreach var in `depvars' {
			
			forvalues n=0/2 {
				sum `var' if treatment==`n' 
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
				}
				matrix `var'= N`var'0,N`var'1,N`var'2\ m`var'0, m`var'1, m`var'2\ sd`var'0, sd`var'1, sd`var'2
				matrix rownames `var'=`var'
				
				
		}
		matrix groups=r2_ch_agemo_trans\r2_s24_q9_trans\r2_ch_haz06_trans\r2_ch_waz06_trans\r2_ch_whz06_trans
		
		frmttable using "$out\Balance_tests_trans_children_new_group", replace sdec(4, 4, 4) statmat(groups)  ///
						title("Balancing Test of New Cohort of Household and Child Characteristics: children's characteristics_v1 of treatment groups") coljust(l;c)  ///
						ctitles("" , Control, OWL, HC) 
			
			
	* test for differences in means *		
		eststo clear
		
		foreach i in `depvars' {
			reg `i' OWL HC , vce(cluster village_code),  
			testparm OWL HC 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	

		xml_tab  *_1, save($out\balance_tests.xls) stats(N pvalue_all) title(OWL vs. HC) sd2 append sheet(trans_children_new) format(SCLR3 NCLR3) keep(OWL HC)
	
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
*	TEST NORMALIZED DIFFERENCES	- NEW COHORT - POOLED TREATMENT	 *
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*	
	*********************************
	*** HOUSEHOLD CHARACTERISTICS ***
	*********************************

	* load household characteristics *
		do "$do/hh characteristics newhh_v1"
	
		sort hhid  
		order hhid treatment hh_size nchildren wives femalehead men_asset_value women_asset_value floor roof anyeduc_head anyeduc_mother 
		
	* merge household attrition indicators and weights *
		merge 1:1 hhid using "$dir\data\hh_attrition.dta", nogen keep (mas mat) keepusing (newHH village_code attrition)
		merge 1:1 hhid using "$dir\data\hh_attrition_weights.dta", nogen keep(mat mas) keepusing(weight)
		sort hhid
	
	* recode baseline-endline attrition status to a binary variable *
		tab attrition, m
		recode attrition (4=0) (5=1), gen(status) 
		lab var status "HH attrited?" 
		lab val status yesno
		tab status, m

	* create treatment indicators *
		g pool=1 if treatment==1 | treatment==2
		replace pool=0 if treatment==0 
		lab val pool yesno
		tab pool treatment, m
		
	* define indicators for balancing test *
		local depvars hh_size nchildren men_asset_value women_asset_value 
		sort hhid

	* test if variables are normally distributed *
		foreach var in `depvars' {
			g `var'_trans=ln(`var') 
			swilk `var'_trans
		}	
		
		local depvars hh_size_trans nchildren_trans men_asset_value_trans women_asset_value_trans
		
	* create table with descriptive statistics for household characteristics *		
		* control, owl and hc groups *
		foreach var in `depvars' {
			
			forvalues n=0/1 {
				sum `var' if pool==`n' & status==0
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
			}
				
				matrix `var'= N`var'0,N`var'1\ m`var'0, m`var'1\ sd`var'0, sd`var'1
				matrix rownames `var'=`var'				
		}
		
		matrix groups=hh_size_trans\nchildren_trans\men_asset_value_trans\women_asset_value_trans

		frmttable using "$out\Balance_tests_trans_newhh_pool", replace sdec(4, 4, 4) statmat(groups)  ///
						title("Balancing Test of New Cohort of Household and Child Characteristics: Household characteristics of treatment groups") ///
						coljust(l;c)  ctitles("" , Control, Pool) 
			
	* test for differences in means *		
		eststo clear
		
		foreach i in `depvars' {
			reg `i' pool if status==0, vce(cluster village_code),  
			testparm pool
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	

		xml_tab  *_1, save($out\balance_tests.xls) stats(N pvalue_all) title(OWL vs. HC) sd2 append sheet(trans_newhh_pool) format(SCLR3 NCLR3) keep(pool)

	********************************
	*** CHILDREN CHARACTERISTICS ***
	********************************

	* load children's characteristics_v1 *
		do "$do/children's characteristics (newhh)_v1"
		
		sort hhid idp_child
		order hhid idp_child treatment ch_sex r2_ch_agemo r2_s24_q9 r2_anemic r2_anemic_severe r2_ch_haz06 r2_stunted r2_ch_waz06 r2_underweight r2_ch_whz06 r2_wasting
		drop idp_mother- diff_wasting
	 	 
	* merge child's attrition status and weights *
		rename idp_child idp 
		merge m:1 hhid idp using "$dir\data\child_attrition.dta", nogen keep (mat) keepusing (attrition newHH)
		merge m:1 hhid idp using "$dir\data\child_attrition_weights.dta", nogen keep(mat) keepusing(weight village_code)
		sort hhid
		
	* recode baseline-endline attrition status to a binary variable *
		tab1 attrition, m
		
		recode attrition (5=0), gen(status)
		label values status yesno
		tab status, m
		lab var status "Child attrited?" 
		sort hhid

	* create treatment indicators *
		g pool=1 if treatment==1 | treatment==2
		replace pool=0 if treatment==0 
		lab val pool yesno
		tab pool treatment, m
		
	* define indicators for balancing test *
		local depvars r2_ch_agemo r2_s24_q9 r2_ch_haz06 r2_ch_waz06 r2_ch_whz06 
		
	* test if variables are normally distributed *
		foreach var in `depvars' {
			g `var'_trans=ln(`var') 
			swilk `var'_trans
		}	
		
		local depvars r2_ch_agemo_trans r2_s24_q9_trans r2_ch_haz06_trans r2_ch_waz06_trans r2_ch_whz06_trans
		
	* create table with descriptive statistics for children's characteristics_v1 *		
		* control, pool groups *
		foreach var in `depvars' {
			
			forvalues n=0/1 {
				sum `var' if pool==`n' 
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
				}
				matrix `var'= N`var'0,N`var'1\ m`var'0, m`var'1\ sd`var'0, sd`var'1
				matrix rownames `var'=`var'
				
				
		}
		matrix groups=r2_ch_agemo_trans\r2_s24_q9_trans\r2_ch_haz06_trans\r2_ch_waz06_trans\r2_ch_whz06_trans
		
		frmttable using "$out\Balance_tests_trans_children_new_pool", replace sdec(4, 4, 4) statmat(groups)  ///
						title("Balancing Test of New Cohort of Household and Child Characteristics: children's characteristics_v1 of treatment groups") coljust(l;c)  ///
						ctitles("" , Control, OWL, HC) 
			
			
	* test for differences in means *		
		eststo clear
		
		foreach i in `depvars' {
			reg `i' pool, vce(cluster village_code),  
			testparm pool
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	

		xml_tab  *_1, save($out\balance_tests.xls) stats(N pvalue_all) title(OWL vs. HC) sd2 append sheet(trans children_new_pool) format(SCLR3 NCLR3) keep(pool)
		
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
* 		TEST NORMALIZED DIFFERENCES	- Balancing Test of Initial Cohort compared to New Cohort  *
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
	*********************************
	*** HOUSEHOLD CHARACTERISTICS ***
	*********************************

	* load household characteristics *
		use "$do/hh_old_new", clear
		
		sort hhid  
		order hhid treatment hh_size nchildren wives femalehead men_asset_value women_asset_value floor roof anyeduc_head anyeduc_mother 
		
	* merge household attrition indicators and weights *
		merge 1:1 hhid using "$dir\data\hh_attrition.dta", nogen keep (mas mat) keepusing (status village_code newHH attrition)
		merge 1:1 hhid using "$dir\data\hh_attrition_weights.dta", nogen keep(mat mas) keepusing(weight)
		sort hhid
				
	* recode status to binary *
		recode status (1=0) (3=1) 
		lab var status "New HH?" 
		lab val status yesno
		tab status, m
		
	* define indicators for balancing test *
		local depvars hh_size nchildren men_asset_value women_asset_value 
		sort hhid
		
	* test if variables are normally distributed *
		foreach var in `depvars' {
			g `var'_trans=ln(`var') 
			swilk `var'_trans
		}	
		
		local depvars hh_size_trans nchildren_trans men_asset_value_trans women_asset_value_trans
		
	* create table with descriptive statistics for household characteristics *
		foreach var in `depvars' {
			
			forvalues n=0/1 {
				sum `var' if status==`n'
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
			}
				
				matrix `var'= N`var'0,N`var'1\ m`var'0, m`var'1\ sd`var'0, sd`var'1
				matrix rownames `var'=`var'
						
		}
		
		matrix groups=hh_size_trans\nchildren_trans\men_asset_value_trans\women_asset_value_trans

		frmttable using "$out\Balance_tests_trans_oldvsnew_hh", replace sdec(4, 4, 4) statmat(groups)  ///
						title("Balancing Test of Initial Cohort compared to New Cohort of Household and Child Characteristics") ///
						coljust(l;c)  ctitles("" , Old HH, New HH) 
			
	* test for differences in means *		
		eststo clear
		
		foreach i in `depvars' {
			reg `i' status, vce(cluster village_code),  
			testparm status
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	

		xml_tab  *_1, save($out\balance_tests.xls) stats(N pvalue_all) title(OWL vs. HC) sd2 append sheet(trans_hh_oldvsnew) format(SCLR3 NCLR3) keep(status)

		
	********************************
	*** CHILDREN CHARACTERISTICS ***
	********************************

	* load household characteristics *
		use "$do/children_old_new", clear
		
		sort hhid idp_child
		order hhid idp_child treatment ch_sex ch_agemo s24_q9 anemic anemic_severe ch_haz06 stunted ch_waz06 underweight ch_whz06 wasting
		
	* merge child's attrition status and weights *
		rename idp_child idp 
		merge m:1 hhid idp using "$dir\data\child_attrition.dta", nogen keep (mat) keepusing (attrition newHH)
		merge m:1 hhid idp using "$dir\data\child_attrition_weights.dta", nogen keep(mat) keepusing(weight village_code)
		sort hhid		
		
	* keep only children 3-12 months of age at baseline *
		keep if ch_agemo>=3 & ch_agemo<=12
		tab newHH, m
					
	* define indicators for balancing test *
		local depvars ch_agemo s24_q9 ch_haz06 ch_waz06 ch_whz06 
		sort hhid
		
	* test if variables are normally distributed *
		foreach var in `depvars' {
			g `var'_trans=ln(`var') 
			swilk `var'_trans
		}	
		
		local depvars ch_agemo_trans s24_q9_trans ch_haz06_trans ch_waz06_trans ch_whz06_trans
		
	* create table with descriptive statistics for household characteristics *
		foreach var in `depvars' {
			
			forvalues n=0/1 {
				sum `var' if newHH==`n'
				matrix N`var'`n'=r(N)
				matrix m`var'`n'=r(mean)
				matrix sd`var'`n'=r(sd)
			}
				
				matrix `var'= N`var'0,N`var'1\ m`var'0, m`var'1\ sd`var'0, sd`var'1
				matrix rownames `var'=`var'
						
		}
		
		matrix groups=ch_agemo_trans\s24_q9_trans\ch_haz06_trans\ch_waz06_trans\ch_whz06_trans

		frmttable using "$out\Balance_tests_trans_oldvsnew_children", replace sdec(4, 4, 4) statmat(groups)  ///
						title("Balancing Test of Initial Cohort compared to New Cohort of Household and Child Characteristics") ///
						coljust(l;c)  ctitles("" , Old HH, New HH) 
			
	* test for differences in means *		
		eststo clear
		
		foreach i in `depvars' {
			reg `i' newHH, vce(cluster village_code),  
			testparm newHH
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	

		xml_tab  *_1, save($out\balance_tests.xls) stats(N pvalue_all) title(OWL vs. HC) sd2 append sheet(trans_children_oldvsnew) format(SCLR3 NCLR3) keep(newHH)
		
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
*			Production Effects of Agricultural Interventions 					*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
	
***	prepare data for merging ***
	local i=1
	
	foreach var in base mid end {
		use "$datam/Section6`var'line.dta", clear
		
		foreach var of varlist plotcount_hh	hec_hh quant_hh	total_mill~h total_bean~h total_sorg~h fert_hh pih_hh man_hh v1_hh v2_hh f1_hh f2_hh f3_hh v1_f v2_f f1_f f2_f f3_f v1_m v2_m f1_m f2_m f3_m plotcount_m plotcount_f hec_m hec_f quant_m quant_f total_mill~m total_mill~f total_sorg~m total_sorg~f total_bean~m total_bean~f fert_m fert_f pih_m pih_f man_m man_f {
			rename `var' r`i'_`var'
		}
		
		lab var weight "Attrition weight (inverse of probability to attrite)"

		save "$do/round`i'", replace
		local i=`i'+1
	}
	
	//-----------------------------------------------------------------------------//
	// 						WOMEN 												   //		
	//-----------------------------------------------------------------------------//
		
	***********************************************
	**** TOTAL EFFECT (2010 - 2013) - old HH   ****	
	***********************************************

	*  merge rounds *
		use "$do/round1", clear
		merge 1:1 hhid  using "$do/round3", nogen keep(match)
			
	* generate pooled treatment indicator *
		gen treat=0 if treatment==0
		replace treat=1 if treatment==1 | treatment==2
		label define treat 1 "Treatment" 0 "Control"
		label values treat treat
		
		foreach i in 1 3 {	
			bys treatment: egen r`i'_plotsum_m=sum(r`i'_plotcount_m)
			bys treatment: egen r`i'_plotsum_f=sum(r`i'_plotcount_f)
			gen r`i'_plotsum_hh=r`i'_plotsum_f + r`i'_plotsum_m
			
			bys treat: egen r`i'_plotsum_joint_m=sum(r`i'_plotcount_m)
			bys treat: egen r`i'_plotsum_joint_f=sum(r`i'_plotcount_f)
			gen r`i'_plotsum_joint_hh=r`i'_plotsum_joint_f + r`i'_plotsum_joint_m 
			
			label var  r`i'_plotsum_joint_m "Total number of plots - men"
			label var  r`i'_plotsum_joint_f "Total number of plots - women"
		}
		
	* keep old cohort households only *
		keep if newHH==0

	* generate differences over time and define indicators of interest *
		foreach var in hec_f plotcount_f quant_f f1_f f2_f f3_f  v2_f fert_f pih_f man_f  {
			g diff_`var'=r3_`var'-r1_`var'
		}

		local diffs diff_hec_f diff_plotcount_f diff_quant_f diff_f1_f diff_f2_f diff_f3_f diff_v2_f diff_fert_f diff_pih_f diff_man_f 
		
	* estimate impact * 
		eststo clear 
		
		foreach i in `diffs' {
				eststo:  reg `i' treat  [pw=weight], vce(cluster village_code)
				testparm treat  
				local pvalue_all=r(p)
				eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}
		
		xml_tab *_1, save($out/agprod.xls) replace stats(N pvalue_all) title("Ag production Impact") b sd2 sheet(Women_old_HH_TE) format(SCLR3 NCLR3) keep(treat )
		
		foreach var in r1_hec_f r1_plotcount_f r1_quant_f r1_f1_f  r1_f2_f r1_f3_f r1_v2_f r1_fert_f r1_pih_f r1_man_f r3_hec_f r3_plotcount_f r3_quant_f r3_f1_f r3_f2_f r3_f3_f r3_v2_f r3_fert_f r3_pih_f r3_man_f {
			mat `var'=J(4,2,.)
			local c=1
			
			forvalue i=0/1 {
				quiet: summ `var' [aw=weight] if treat==`i'
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				matrix `var'[4,`c']=.
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'  " "
			mat list `var'
		}
		
		matrix all=r1_hec_f\r1_plotcount_f\r1_quant_f\r1_f1_f\r1_f2_f\r1_f3_f\r1_v2_f\r1_fert_f\r1_pih_f\r1_man_f\r3_hec_f\r3_plotcount_f\r3_quant_f\r3_f1_f\r3_f2_f\r3_f3_f\r3_v2_f\r3_fert_f\r3_pih_f\r3_man_f

		mat colnames all = "Control" "Treatment"
		mat list all

		frmttable using "$out/Ag Production Women old HH TE", replace sdec(2,2,2) statmat(all) coljust(l;c) ctitles("", Control, Treatment)	

	**********************************************
	**** LATER EFFECT (2012-2013) - old HH    ****	
	**********************************************

	*  merge rounds *
		use "$do/round2", clear
		merge 1:1 hhid  using "$do/round3", nogen keep(match)

	* generate pooled treatment indicator *
		gen treat=0 if treatment==0
		replace treat=1 if treatment==1 | treatment==2
		label define treat 1 "Treatment" 0 "Control"
		label values treat treat
		
		forvalues i=2/3 {	
			bys treatment: egen r`i'_plotsum_m=sum(r`i'_plotcount_m)
			bys treatment: egen r`i'_plotsum_f=sum(r`i'_plotcount_f)
			gen r`i'_plotsum_hh=r`i'_plotsum_f + r`i'_plotsum_m
			
			bys treat: egen r`i'_plotsum_joint_m=sum(r`i'_plotcount_m)
			bys treat: egen r`i'_plotsum_joint_f=sum(r`i'_plotcount_f)
			gen r`i'_plotsum_joint_hh=r`i'_plotsum_joint_f + r`i'_plotsum_joint_m 
			
			label var  r`i'_plotsum_joint_m "Total number of plots - men"
			label var  r`i'_plotsum_joint_f "Total number of plots - women"
		}
			
	* keep old cohort households only *
		keep if newHH==0
		
	* genera differences over time and define variables of interest *
		foreach var in hec_f plotcount_f quant_f f1_f f2_f f3_f  v2_f fert_f pih_f man_f  {
			g diff_`var'=r3_`var'-r2_`var'
		}

		local diffs diff_hec_f diff_plotcount_f diff_quant_f diff_f1_f diff_f2_f diff_f3_f  diff_v2_f diff_fert_f diff_pih_f diff_man_f 
		
	* estimate impact * 
		eststo clear 
		
		foreach i in `diffs' {
				eststo:  reg `i' treat  [pw=weight], vce(cluster village_code)
				testparm treat  
				local pvalue_all=r(p)
				eststo `i'_1, addscalars(pvalue_all `pvalue_all')
																}		
		xml_tab *_1, save($out/agprod.xls) append stats(N pvalue_all) title("Ag production Impact") b sd2 sheet(Women_old_HH_LE) format(SCLR3 NCLR3) keep(treat )
		
		foreach var in r2_hec_f r2_plotcount_f r2_quant_f r2_f1_f  r2_f2_f r2_f3_f r2_v2_f r2_fert_f r2_pih_f r2_man_f r3_hec_f r3_plotcount_f r3_quant_f r3_f1_f r3_f2_f r3_f3_f r3_v2_f r3_fert_f r3_pih_f r3_man_f {
			mat `var'=J(4,2,.)
			local c=1
			
			forvalue i=0/1 {
				quiet: summ `var' [aw=weight] if treat==`i'
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				matrix `var'[4,`c']=.
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'  " "
			mat list `var'
		}
		
		matrix all=r2_hec_f\r2_plotcount_f\r2_quant_f\r2_f1_f\r2_f2_f\r2_f3_f\r2_v2_f\r2_fert_f\r2_pih_f\r2_man_f\r3_hec_f\r3_plotcount_f\r3_quant_f\r3_f1_f\r3_f2_f\r3_f3_f\r3_v2_f\r3_fert_f\r3_pih_f\r3_man_f

		mat colnames all = "Control" "Treatment"
		mat list all

		frmttable using "$out/Ag Production Women old HH LE", replace sdec(2,2,2) statmat(all) coljust(l;c) ctitles("", Control, Treatment)	

	**********************************************
	**** EARLY EFFECT (2010-2012) - old HH    ****	
	**********************************************
	
	* merge rounds *
		use "$do/round1", clear
		merge 1:1 hhid  using "$do/round2",  nogen keep(match)

	* generate pooled treatment indicator *
		gen treat=0 if treatment==0
		replace treat=1 if treatment==1 | treatment==2
		label define treat 1 "Treatment" 0 "Control"
		label values treat treat
		
		forvalues i=1/2 {	
			bys treatment: egen r`i'_plotsum_m=sum(r`i'_plotcount_m)
			bys treatment: egen r`i'_plotsum_f=sum(r`i'_plotcount_f)
			gen r`i'_plotsum_hh=r`i'_plotsum_f + r`i'_plotsum_m
			
			bys treat: egen r`i'_plotsum_joint_m=sum(r`i'_plotcount_m)
			bys treat: egen r`i'_plotsum_joint_f=sum(r`i'_plotcount_f)
			gen r`i'_plotsum_joint_hh=r`i'_plotsum_joint_f + r`i'_plotsum_joint_m 
			
			label var  r`i'_plotsum_joint_m "Total number of plots - men"
			label var  r`i'_plotsum_joint_f "Total number of plots - women"
		}
			
	* keep old cohort households only *
		keep if newHH==0
					
	* generate differences over time and define variables of interest *
		foreach var in hec_f plotcount_f quant_f f1_f f2_f f3_f  v2_f fert_f pih_f man_f  {
			g diff_`var'=r2_`var'-r1_`var'
		}

		local diffs diff_hec_f diff_plotcount_f diff_quant_f diff_f1_f diff_f2_f diff_f3_f  diff_v2_f diff_fert_f diff_pih_f diff_man_f 	
		
	* estimate impact * 
		eststo clear 
		
		foreach i in `diffs' {
				eststo:  reg `i' treat  [pw=weight], vce(cluster village_code)
				testparm treat  
				local pvalue_all=r(p)
				eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	
		
		xml_tab *_1, save($out/agprod.xls) append stats(N pvalue_all) title("Ag production Impact") b sd2 sheet(Women_old_HH_EE) format(SCLR3 NCLR3) keep(treat)
		
		foreach var in r1_hec_f r1_plotcount_f r1_quant_f r1_f1_f  r1_f2_f r1_f3_f r1_v2_f r1_fert_f r1_pih_f r1_man_f r2_hec_f r2_plotcount_f r2_quant_f r2_f1_f r2_f2_f r2_f3_f r2_v2_f r2_fert_f r2_pih_f r2_man_f {
			mat `var'=J(4,2,.)
			local r=1 
			local c=1
			
			forvalue i=0/1 {
				quiet: summ `var' [aw=weight] if treat==`i'
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				matrix `var'[4,`c']=.
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'  " "
			mat list `var'
		}
		
		matrix all=r1_hec_f\r1_plotcount_f\r1_quant_f\r1_f1_f\r1_f2_f\r1_f3_f\r1_v2_f\r1_fert_f\r1_pih_f\r1_man_f\r2_hec_f\r2_plotcount_f\r2_quant_f\r2_f1_f\r2_f2_f\r2_f3_f\r2_v2_f\r2_fert_f\r2_pih_f\r2_man_f

		mat colnames all = "Control" "Treatment"
		mat list all

		frmttable using "$out/Ag Production Women old HH EE", replace sdec(2,2,2) statmat(all) coljust(l;c) ctitles("", Control, Treatment)	

		
	********************************************
	**** TOTAL EFFECT (2012 - 2013) - newHH ****	
	********************************************
		
	* merge rounds *
		use "$do/round2", clear
		merge 1:1 hhid  using "$do/round3", nogen keep(match)
		
	* generate pooled treatment indicator *
		gen treat=0 if treatment==0
		replace treat=1 if treatment==1 | treatment==2
		label define treat 1 "Treatment" 0 "Control"
		label values treat treat
		
		forvalues i=2/3 {	
			bys treatment: egen r`i'_plotsum_m=sum(r`i'_plotcount_m)
			bys treatment: egen r`i'_plotsum_f=sum(r`i'_plotcount_f)
			gen r`i'_plotsum_hh=r`i'_plotsum_f + r`i'_plotsum_m
			
			bys treat: egen r`i'_plotsum_joint_m=sum(r`i'_plotcount_m)
			bys treat: egen r`i'_plotsum_joint_f=sum(r`i'_plotcount_f)
			gen r`i'_plotsum_joint_hh=r`i'_plotsum_joint_f + r`i'_plotsum_joint_m 
			
			label var  r`i'_plotsum_joint_m "Total number of plots - men"
			label var  r`i'_plotsum_joint_f "Total number of plots - women"
		}
			
	* keep old cohort households only *
		keep if newHH==1
					
	* generate differences over time and define variables of interest *
		foreach var in hec_f plotcount_f quant_f f1_f f2_f f3_f  v2_f fert_f pih_f man_f  {
			g diff_`var'=r3_`var'-r2_`var'
		}

		local diffs diff_hec_f diff_plotcount_f diff_quant_f diff_f1_f diff_f2_f diff_f3_f  diff_v2_f diff_fert_f diff_pih_f diff_man_f 	
		
	* estimate impact * 
		eststo clear 
		
		foreach i in `diffs' {
				eststo:  reg `i' treat  [pw=weight], vce(cluster village_code)
				testparm treat  
				local pvalue_all=r(p)
				eststo `i'_1, addscalars(pvalue_all `pvalue_all')
																}		
		xml_tab *_1, save($out/agprod.xls) append stats(N pvalue_all) title("Ag production Impact") b sd2 sheet(Women_new_HH_TE) format(SCLR3 NCLR3) keep(treat)
		
		foreach var in r2_hec_f r2_plotcount_f r2_quant_f r2_f1_f  r2_f2_f r2_f3_f r2_v2_f r2_fert_f r2_pih_f r2_man_f r3_hec_f r3_plotcount_f r3_quant_f r3_f1_f r3_f2_f r3_f3_f r3_v2_f r3_fert_f r3_pih_f r3_man_f {
			mat `var'=J(4,2,.)
			local c=1
			
			forvalue i=0/1 {
				quiet: summ `var' [aw=weight] if treat==`i'
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				matrix `var'[4,`c']=.
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'  " "
			mat list `var'
		}
		
		matrix all=r2_hec_f\r2_plotcount_f\r2_quant_f\r2_f1_f\r2_f2_f\r2_f3_f\r2_v2_f\r2_fert_f\r2_pih_f\r2_man_f\r3_hec_f\r3_plotcount_f\r3_quant_f\r3_f1_f\r3_f2_f\r3_f3_f\r3_v2_f\r3_fert_f\r3_pih_f\r3_man_f

		mat colnames all = "Control" "Treatment"
		mat list all

		frmttable using "$out/Ag Production Women new HH TE", replace sdec(2,2,2) statmat(all) coljust(l;c) ctitles("", Control, Treatment)	


	//-----------------------------------------------------------------------------//
	// 						MEN 												   //		
	//-----------------------------------------------------------------------------//


	***********************************************
	**** TOTAL EFFECT (2010 - 2013) - old HH   ****	
	***********************************************
		
	* merge rounds *
		use "$do/round1", clear
		merge 1:1 hhid using "$do/round3", nogen keep(match)
		
	* generate pooled treatment indicator *
		gen treat=0 if treatment==0
		replace treat=1 if treatment==1 | treatment==2
		label define treat 1 "Treatment" 0 "Control"
		label values treat treat
		
		foreach i in   1 3 {	
			bys treatment: egen r`i'_plotsum_m=sum(r`i'_plotcount_m)
			bys treatment: egen r`i'_plotsum_f=sum(r`i'_plotcount_f)
			gen r`i'_plotsum_hh=r`i'_plotsum_f + r`i'_plotsum_m
			
			bys treat: egen r`i'_plotsum_joint_m=sum(r`i'_plotcount_m)
			bys treat: egen r`i'_plotsum_joint_f=sum(r`i'_plotcount_f)
			gen r`i'_plotsum_joint_hh=r`i'_plotsum_joint_f + r`i'_plotsum_joint_m 
			
			label var  r`i'_plotsum_joint_m "Total number of plots - men"
			label var  r`i'_plotsum_joint_f "Total number of plots - women"
		}
						
	* keep old cohort households only *
		keep if newHH==0
					
	* generate differences over time and define variables of interest *
		foreach var in hec_m plotcount_m quant_m f1_m f2_m f3_m  v2_m fert_m pih_m man_m  {
			g diff_`var'=r3_`var'-r1_`var'
		}

		local diffs diff_hec_m diff_plotcount_m diff_quant_m diff_f1_m diff_f2_m diff_f3_m  diff_v2_m diff_fert_m diff_pih_m diff_man_m 	
		
	* estimate impact * 
		eststo clear 
		
		foreach i in `diffs' {
				eststo:  reg `i' treat  [pw=weight], vce(cluster village_code)
				testparm treat  
				local pvalue_all=r(p)
				eststo `i'_1, addscalars(pvalue_all `pvalue_all')
																}		
		xml_tab *_1, save($out/agprod.xls) append stats(N pvalue_all) title("Ag production Impact") b sd2 sheet(men_old_HH_TE) format(SCLR3 NCLR3) keep(treat)
		
		foreach var in r1_hec_m r1_plotcount_m r1_quant_m r1_f1_m  r1_f2_m r1_f3_m r1_v2_m r1_fert_m r1_pih_m r1_man_m r3_hec_m r3_plotcount_m r3_quant_m r3_f1_m r3_f2_m r3_f3_m r3_v2_m r3_fert_m r3_pih_m r3_man_m {
			mat `var'=J(4,2,.)
			local c=1
			
			forvalue i=0/1 {
				quiet: summ `var' [aw=weight] if treat==`i'
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				matrix `var'[4,`c']=.
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'  " "
			mat list `var'
		}
		
		matrix all=r1_hec_m\r1_plotcount_m\r1_quant_m\r1_f1_m\r1_f2_m\r1_f3_m\r1_v2_m\r1_fert_m\r1_pih_m\r1_man_m\r3_hec_m\r3_plotcount_m\r3_quant_m\r3_f1_m\r3_f2_m\r3_f3_m\r3_v2_m\r3_fert_m\r3_pih_m\r3_man_m

		mat colnames all = "Control" "Treatment"
		mat list all

		frmttable using "$out/Ag Production Men old HH TE", replace sdec(2,2,2) statmat(all) coljust(l;c) ctitles("", Control, Treatment)	

	**********************************************
	**** LATER EFFECT (2012-2013) - old HH    ****	
	**********************************************
	
	* merge rounds *
		use "$do/round2", clear
		merge 1:1 hhid  using "$do/round3", nogen keep(match)
		
	* generate pooled treatment indicator *
		gen treat=0 if treatment==0
		replace treat=1 if treatment==1 | treatment==2
		label define treat 1 "Treatment" 0 "Control"
		label values treat treat
		
		forvalues i=2/3 {	
			bys treatment: egen r`i'_plotsum_m=sum(r`i'_plotcount_m)
			bys treatment: egen r`i'_plotsum_f=sum(r`i'_plotcount_f)
			gen r`i'_plotsum_hh=r`i'_plotsum_f + r`i'_plotsum_m
			
			bys treat: egen r`i'_plotsum_joint_m=sum(r`i'_plotcount_m)
			bys treat: egen r`i'_plotsum_joint_f=sum(r`i'_plotcount_f)
			gen r`i'_plotsum_joint_hh=r`i'_plotsum_joint_f + r`i'_plotsum_joint_m 
			
			label var  r`i'_plotsum_joint_m "Total number of plots - men"
			label var  r`i'_plotsum_joint_f "Total number of plots - women"
		}
			
	* keep old cohort households only *
		keep if newHH==0
					
	* generate differences over time and define variables of interest *
		foreach var in hec_m plotcount_m quant_m f1_m f2_m f3_m  v2_m fert_m pih_m man_m  {
			g diff_`var'=r3_`var'-r2_`var'
		}

		local diffs diff_hec_m diff_plotcount_m diff_quant_m diff_f1_m diff_f2_m diff_f3_m  diff_v2_m diff_fert_m diff_pih_m diff_man_m 	
		
	* estimate impact * 
		eststo clear 
		
		foreach i in `diffs' {
				eststo:  reg `i' treat  [pw=weight], vce(cluster village_code)
				testparm treat  
				local pvalue_all=r(p)
				eststo `i'_1, addscalars(pvalue_all `pvalue_all')
																}		
		xml_tab *_1, save($out/agprod.xls) append stats(N pvalue_all) title("Ag production Impact") b sd2 sheet(men_old_HH_LE) format(SCLR3 NCLR3) keep(treat)
		
		foreach var in r2_hec_m r2_plotcount_m r2_quant_m r2_f1_m  r2_f2_m r2_f3_m r2_v2_m r2_fert_m r2_pih_m r2_man_m r3_hec_m r3_plotcount_m r3_quant_m r3_f1_m r3_f2_m r3_f3_m r3_v2_m r3_fert_m r3_pih_m r3_man_m {
			mat `var'=J(4,2,.)
			local c=1
			
			forvalue i=0/1 {
				quiet: summ `var' [aw=weight] if treat==`i'
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				matrix `var'[4,`c']=.
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'  " "
			mat list `var'
		}
		
		matrix all=r2_hec_m\r2_plotcount_m\r2_quant_m\r2_f1_m\r2_f2_m\r2_f3_m\r2_v2_m\r2_fert_m\r2_pih_m\r2_man_m\r3_hec_m\r3_plotcount_m\r3_quant_m\r3_f1_m\r3_f2_m\r3_f3_m\r3_v2_m\r3_fert_m\r3_pih_m\r3_man_m

		mat colnames all = "Control" "Treatment"
		mat list all

		frmttable using "$out/Ag Production Men old HH LE", replace sdec(2,2,2) statmat(all) coljust(l;c) ctitles("", Control, Treatment)	


	**********************************************
	**** EARLY EFFECT (2010-2012) - old HH    ****	
	**********************************************
	
	* merge rounds *
		use "$do/round1", clear
		merge 1:1 hhid  using "$do/round2", nogen keep(match)
		
	* generate pooled treatment indicator *
		gen treat=0 if treatment==0
		replace treat=1 if treatment==1 | treatment==2
		label define treat 1 "Treatment" 0 "Control"
		label values treat treat
		
		forvalues i=1/2 {	
			bys treatment: egen r`i'_plotsum_m=sum(r`i'_plotcount_m)
			bys treatment: egen r`i'_plotsum_f=sum(r`i'_plotcount_f)
			gen r`i'_plotsum_hh=r`i'_plotsum_f + r`i'_plotsum_m
			
			bys treat: egen r`i'_plotsum_joint_m=sum(r`i'_plotcount_m)
			bys treat: egen r`i'_plotsum_joint_f=sum(r`i'_plotcount_f)
			gen r`i'_plotsum_joint_hh=r`i'_plotsum_joint_f + r`i'_plotsum_joint_m 
			
			label var  r`i'_plotsum_joint_m "Total number of plots - men"
			label var  r`i'_plotsum_joint_f "Total number of plots - women"
		}
			
	* keep old cohort households only *
		keep if newHH==0
					
	* generate differences over time and define variables of interest *
		foreach var in hec_m plotcount_m quant_m f1_m f2_m f3_m  v2_m fert_m pih_m man_m  {
			g diff_`var'=r2_`var'-r1_`var'
		}

		local diffs diff_hec_m diff_plotcount_m  diff_quant_m diff_f1_m diff_f2_m diff_f3_m  diff_v2_m diff_fert_m diff_pih_m diff_man_m 	
		
	* estimate impact * 
		eststo clear 
		
		foreach i in `diffs' {
				eststo:  reg `i' treat  [pw=weight], vce(cluster village_code)
				testparm treat  
				local pvalue_all=r(p)
				eststo `i'_1, addscalars(pvalue_all `pvalue_all')
																}		
		xml_tab *_1, save($out/agprod.xls) append stats(N pvalue_all) title("Ag production Impact") b sd2 sheet(men_old_HH_EE) format(SCLR3 NCLR3) keep(treat)
		
		foreach var in r1_hec_m r1_plotcount_m r1_quant_m r1_f1_m r1_f2_m r1_f3_m r1_v2_m r1_fert_m r1_pih_m r1_man_m r2_hec_m r2_plotcount_m r2_quant_m r2_f1_m r2_f2_m r2_f3_m r2_v2_m r2_fert_m r2_pih_m r2_man_m {
			mat `var'=J(4,2,.)
			local c=1
			
			forvalue i=0/1 {
				quiet: summ `var' [aw=weight] if treat==`i'
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				matrix `var'[4,`c']=.
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'  " "
			mat list `var'
		}
		
		matrix all=r1_hec_m\r1_plotcount_m\r1_quant_m\r1_f1_m\r1_f2_m\r1_f3_m\r1_v2_m\r1_fert_m\r1_pih_m\r1_man_m\r2_hec_m\r2_plotcount_m\r2_quant_m\r2_f1_m\r2_f2_m\r2_f3_m\r2_v2_m\r2_fert_m\r2_pih_m\r2_man_m

		mat colnames all = "Control" "Treatment"
		mat list all

		frmttable using "$out/Ag Production Men old HH EE", replace sdec(2,2,2) statmat(all) coljust(l;c) ctitles("", Control, Treatment)	
		
	********************************************
	**** TOTAL EFFECT (2012 - 2013) - newHH ****	
	********************************************
		
	* merge rounds *
		use "$do/round2", clear
		merge 1:1 hhid  using "$do/round3", nogen keep(match)
		
	* generate pooled treatment indicator *
		gen treat=0 if treatment==0
		replace treat=1 if treatment==1 | treatment==2
		label define treat 1 "Treatment" 0 "Control"
		label values treat treat
		
		forvalues i=2/3 {	
			bys treatment: egen r`i'_plotsum_m=sum(r`i'_plotcount_m)
			bys treatment: egen r`i'_plotsum_f=sum(r`i'_plotcount_f)
			gen r`i'_plotsum_hh=r`i'_plotsum_f + r`i'_plotsum_m
			
			bys treat: egen r`i'_plotsum_joint_m=sum(r`i'_plotcount_m)
			bys treat: egen r`i'_plotsum_joint_f=sum(r`i'_plotcount_f)
			gen r`i'_plotsum_joint_hh=r`i'_plotsum_joint_f + r`i'_plotsum_joint_m 
			
			label var  r`i'_plotsum_joint_m "Total number of plots - men"
			label var  r`i'_plotsum_joint_f "Total number of plots - women"
		}
			
	* keep old cohort households only *
		keep if newHH==1
					
	* generate differences over time and define variables of interest *
		foreach var in hec_m plotcount_m quant_m f1_m f2_m f3_m  v2_m fert_m pih_m man_m  {
			g diff_`var'=r3_`var'-r2_`var'
		}

		local diffs diff_hec_m diff_plotcount_m diff_quant_m diff_f1_m diff_f2_m diff_f3_m  diff_v2_m diff_fert_m diff_pih_m diff_man_m 	
		
	* estimate impact * 
		eststo clear 
		
		foreach i in `diffs' {
				eststo:  reg `i' treat  [pw=weight], vce(cluster village_code)
				testparm treat  
				local pvalue_all=r(p)
				eststo `i'_1, addscalars(pvalue_all `pvalue_all')
																}		
		xml_tab *_1, save($out/agprod.xls) append stats(N pvalue_all) title("Ag production Impact") b sd2 sheet(men_new_HH_TE) format(SCLR3 NCLR3) keep(treat)
		
		foreach var in r2_hec_m r2_plotcount_m r2_quant_m r2_f1_m  r2_f2_m r2_f3_m r2_v2_m r2_fert_m r2_pih_m r2_man_m r3_hec_m r3_plotcount_m r3_quant_m r3_f1_m r3_f2_m r3_f3_m r3_v2_m r3_fert_m r3_pih_m r3_man_m {
			mat `var'=J(4,2,.)
			local c=1
			
			forvalue i=0/1 {
				quiet: summ `var' [aw=weight] if treat==`i'
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				matrix `var'[4,`c']=.
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'  " "
			mat list `var'
		}
		
		matrix all=r2_hec_m\r2_plotcount_m\r2_quant_m\r2_f1_m\r2_f2_m\r2_f3_m\r2_v2_m\r2_fert_m\r2_pih_m\r2_man_m\r3_hec_m\r3_plotcount_m\r3_quant_m\r3_f1_m\r3_f2_m\r3_f3_m\r3_v2_m\r3_fert_m\r3_pih_m\r3_man_m

		mat colnames all = "Control" "Treatment"
		mat list all


		frmttable using "$out/Ag Production Men new HH TE", replace sdec(2,2,2) statmat(all) coljust(l;c) ctitles("", Control, Treatment)
		
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
*	Feeding Practices and Health Care Knowledge Effects of BCC Interventions   *
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*

* prepare data for merge *
	tokenize data2010 data2012 data2013 
	local j=1
	
	forvalue i=1/3 {
		if `i'==1 {
			use "$``j''/R`i'_Section_18", clear
		}
		else {
			use "$``j''/R`i'_Section_18_Mom", clear
		}
			* Generate pooled treatment indicator *
				gen treatotal=0 if !missing(treatment)
				replace treatotal=1 if treatment==1 | treatment==2
				
				foreach var of varlist * {
					rename `var' r`i'_`var'
				}
				
				foreach x in hhid idp_child idp_mother treatotal treatment newHH {
					rename r`i'_`x' `x'
				}
			
			* Recode variables for analysis *
				gen r`i'_s18_q1_1=0 if !missing(r`i'_s18_q1)
				replace r`i'_s18_q1_1=1 if r`i'_s18_q1==6 & !missing(r`i'_s18_q1)
				
				gen r`i'_s18_q1_2=0 if !missing(r`i'_s18_q1)
				replace r`i'_s18_q1_2=1 if r`i'_s18_q1<6 & !missing(r`i'_s18_q1)
				
				gen r`i'_s18_q1_3=0 if !missing(r`i'_s18_q1)
				replace r`i'_s18_q1_3=1 if r`i'_s18_q1>6 & !missing(r`i'_s18_q1)
			
				gen r`i'_s18_q2_1=0 if !missing(r`i'_s18_q2)
				replace r`i'_s18_q2_1=1 if r`i'_s18_q2==6 & !missing(r`i'_s18_q2)
				
				gen r`i'_s18_q2_2=0 if !missing(r`i'_s18_q2)
				replace r`i'_s18_q2_2=1 if r`i'_s18_q2<6 & !missing(r`i'_s18_q2)
				
				gen r`i'_s18_q2_3=0 if !missing(r`i'_s18_q2)
				replace r`i'_s18_q2_3=1 if r`i'_s18_q2>6 & !missing(r`i'_s18_q2)
					
				replace r`i'_s18_q3_2=1 if r`i'_s18_q3_1==1

				recode r`i'_s18_q10 (0=2) 
				recode r`i'_s18_q10 (1=0) 
				recode r`i'_s18_q10 (2=1)
				label value r`i'_s18_q10			
				
				duplicates drop hhid idp_mother, force
				sort hhid idp_mother
			save "$do/r`i's18", replace 
			local j=`j'+1
		}

************************************************************
*** Knowledge of feeding practices of primary caregivers ***
************************************************************
		
* merge rounds for total effect. merge attrition weights *
	use "$do/r1s18", clear
	merge 1:1 hhid idp_mother using "$do/r2s18", keep(mat) nogen
	merge 1:1 hhid idp_mother using "$do/r3s18", keep(mat) nogen
	merge m:1 hhid using "$dir/data/hh_attrition_weights", keepusing(weight village_code) nogen keep(mas mat)
	
	******************************************************************
	**** TOTAL EFFECT (2010 - 2013) - Women in old HH   (Panel C) ****	
	******************************************************************

	* gen treatment group indicators *
		gen owl=1 if treatment==1
		replace owl=0 if treatment==0 | treatment==2
		lab var owl "OWL group"
		
		gen hc=1 if treatment==2 
		replace hc=0 if treatment==0 | treatment==1
		lab var hc "HC group"

	* generate differences over time *
		* generate a var for immediate or <1 hour bf for all 3 rounds. the rest are fine, but need labelling 
		
		forvalue i=1/3 {
			g r`i'_s18_q3_7=1 if r`i'_s18_q3_2==1 | r`i'_s18_q3_1==1
			replace r`i'_s18_q3_7=0 if r`i'_s18_q3_7==.
		}

		foreach var in 	s18_q3_7 s18_q4_2 s18_q10 s18_q1_1 s18_q2_1 s18_q18_1 s18_q18_2 s18_q18_3 s18_q18_4 {
			replace r1_`var'=. if r2_`var'==.
			replace r1_`var'=. if r3_`var'==.
			replace r2_`var'=. if r1_`var'==.
			replace r2_`var'=. if r3_`var'==.
			replace r3_`var'=. if r1_`var'==.
			replace r3_`var'=. if r2_`var'==.
			g diff_`var'=r3_`var'-r1_`var'
			}
		
		local diffs diff_s18_q3_7 diff_s18_q4_2 diff_s18_q10 diff_s18_q1_1 diff_s18_q2_1 diff_s18_q18_1 diff_s18_q18_2 diff_s18_q18_3 diff_s18_q18_4
		
	* estimate impact * 
		eststo clear 
		
		foreach i in `diffs' {
			eststo: noisily reg `i' owl hc [pw=weight], vce(cluster village_code)
			testparm owl hc 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	
		
		xml_tab *_1, save($out/knowledge.xls) replace stats(N pvalue_all) title("Knowledge of feeding practices") b sd2 sheet(feed_old_TE) format(SCLR3 NCLR3) keep(owl hc)
		
		foreach var in r1_s18_q3_7 r1_s18_q4_2 r1_s18_q10 r1_s18_q1_1 r1_s18_q2_1 r1_s18_q18_1 r1_s18_q18_2 r1_s18_q18_3 r1_s18_q18_4 r3_s18_q3_7 r3_s18_q4_2 r3_s18_q10 r3_s18_q1_1 r3_s18_q2_1 r3_s18_q18_1 r3_s18_q18_2 r3_s18_q18_3 r3_s18_q18_4 {
			mat `var'=J(3,3,.)
			local c=1
			
			forvalue i=0/2 {
				summ `var' [aw=weight] if treatment==`i'
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'
			mat list `var'
		}
		
		matrix all=r1_s18_q3_7\r3_s18_q3_7\r1_s18_q4_2\r3_s18_q4_2\r1_s18_q10\r3_s18_q10\r1_s18_q1_1\r3_s18_q1_1\r1_s18_q2_1\r3_s18_q2_1\r1_s18_q18_1\r3_s18_q18_1\r1_s18_q18_2\r3_s18_q18_2\r1_s18_q18_3\r3_s18_q18_3\r1_s18_q18_4\r3_s18_q18_4  
		mat colnames all = "Control" "OWL" "HC"
		mat list all

		frmttable using "$out/Knowledge Feeding Women old HH TE", replace sdec(2,2,2) statmat(all) coljust(l;c) ctitles("", Control, OWL, HC)	
		
			
	******************************************************************
	**** EARLY EFFECT (2010 - 2012) - Womein in old HH  (Panel A) ****	
	******************************************************************
		
	* generate differences over time *
		drop diff*
		
		foreach var in 	s18_q3_7 s18_q4_2 s18_q10 s18_q1_1 s18_q2_1 s18_q18_1 s18_q18_2 s18_q18_3 s18_q18_4 {
			g diff_`var'=r2_`var'-r1_`var'
		}
		
		local diffs diff_s18_q3_7 diff_s18_q4_2 diff_s18_q10 diff_s18_q1_1 diff_s18_q2_1 diff_s18_q18_1 diff_s18_q18_2 diff_s18_q18_3 diff_s18_q18_4
		
	* estimate impact * 
		eststo clear 
		
		foreach i in `diffs' {
			eststo: noisily reg `i' owl hc [pw=weight], vce(cluster village_code)
			testparm owl hc 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	
		
		xml_tab *_1, save($out/knowledge.xls) append stats(N pvalue_all) title("Knowledge of feeding practices") b sd2 sheet(feed_old_EE) format(SCLR3 NCLR3) keep(owl hc)
		
		foreach var in r1_s18_q3_7 r1_s18_q4_2 r1_s18_q10 r1_s18_q1_1 r1_s18_q2_1 r1_s18_q18_1 r1_s18_q18_2 r1_s18_q18_3 r1_s18_q18_4 r2_s18_q3_7 r2_s18_q4_2 r2_s18_q10 r2_s18_q1_1 r2_s18_q2_1 r2_s18_q18_1 r2_s18_q18_2 r2_s18_q18_3 r2_s18_q18_4 {
			mat `var'=J(3,3,.)
			local c=1
			
			forvalue i=0/2 {
				summ `var' [aw=weight] if treatment==`i'
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'
			mat list `var'
		}
		
		matrix all=r1_s18_q3_7\r2_s18_q3_7\r1_s18_q4_2\r2_s18_q4_2\r1_s18_q10\r2_s18_q10\r1_s18_q1_1\r2_s18_q1_1\r1_s18_q2_1\r2_s18_q2_1\r1_s18_q18_1\r2_s18_q18_1\r1_s18_q18_2\r2_s18_q18_2\r1_s18_q18_3\r2_s18_q18_3\r1_s18_q18_4\r2_s18_q18_4  
		mat colnames all = "Control" "OWL" "HC"
		mat list all

		frmttable using "$out/Knowledge Feeding Women old HH EE", replace sdec(2,2,2) statmat(all) coljust(l;c) ctitles("", Control, OWL, HC)	
		
	**************************************************************
	**** LATER EFFECT (2012-2013) - Women in old HH (Panel B) ****	
	**************************************************************

	* generate differences over time *
		drop diff*
		
		foreach var in 	s18_q3_7 s18_q4_2 s18_q10 s18_q1_1 s18_q2_1 s18_q18_1 s18_q18_2 s18_q18_3 s18_q18_4 {
			g diff_`var'=r3_`var'-r2_`var'
		}
		
		local diffs diff_s18_q3_7 diff_s18_q4_2 diff_s18_q10 diff_s18_q1_1 diff_s18_q2_1 diff_s18_q18_1 diff_s18_q18_2 diff_s18_q18_3 diff_s18_q18_4
		
	* estimate impact * 
		eststo clear 
		
		foreach i in `diffs' {
			eststo: noisily reg `i' owl hc [pw=weight], vce(cluster village_code)
			testparm owl hc 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	
		
		xml_tab *_1, save($out/knowledge.xls) append stats(N pvalue_all) title("Knowledge of feeding practices") b sd2 sheet(feed_old_LE) format(SCLR3 NCLR3) keep(owl hc)
		
		foreach var in r2_s18_q3_7 r2_s18_q4_2 r2_s18_q10 r2_s18_q1_1 r2_s18_q2_1 r2_s18_q18_1 r2_s18_q18_2 r2_s18_q18_3 r2_s18_q18_4 r3_s18_q3_7 r3_s18_q4_2 r3_s18_q10 r3_s18_q1_1 r3_s18_q2_1 r3_s18_q18_1 r3_s18_q18_2 r3_s18_q18_3 r3_s18_q18_4 {
			mat `var'=J(3,3,.)
			local c=1
			
			forvalue i=0/2 {
				summ `var' [aw=weight] if treatment==`i'
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'
			mat list `var'
		}
		
		matrix all=r2_s18_q3_7\r3_s18_q3_7\r2_s18_q4_2\r3_s18_q4_2\r2_s18_q10\r3_s18_q10\r2_s18_q1_1\r3_s18_q1_1\r2_s18_q2_1\r3_s18_q2_1\r2_s18_q18_1\r3_s18_q18_1\r2_s18_q18_2\r3_s18_q18_2\r2_s18_q18_3\r3_s18_q18_3\r2_s18_q18_4\r3_s18_q18_4  
		mat colnames all = "Control" "OWL" "HC"
		mat list all

		frmttable using "$out/Knowledge Feeding Women Old HH LE", replace sdec(2,2,2) statmat(all) coljust(l;c) ctitles("", Control, OWL, HC)	
		
	********************************************************************
	**** TOTAL EFFECT (2012 - 2013) - Women in newHH only (Panel D) ****	
	********************************************************************

* merge rounds for total effect. merge attrition weights *
	use "$do/r2s18", clear
	merge 1:1 hhid idp_mother using "$do/r3s18", keep(mat) nogen
	merge m:1 hhid using "$dir/data/hh_attrition_weights", keepusing(weight village_code) nogen keep(mas mat)

* keep new households only *	
	keep if newHH==1		
			
	* gen treatment group indicators *
		gen owl=1 if treatment==1
		replace owl=0 if treatment==0 | treatment==2
		lab var owl "OWL group"
		
		gen hc=1 if treatment==2 
		replace hc=0 if treatment==0 | treatment==1
		lab var hc "HC group"

	* generate differences over time *
		* generate a var for immediate or <1 hour bf for all 3 rounds. the rest are fine, but need labelling 
		
		forvalue i=2/3 {
			g r`i'_s18_q3_7=1 if r`i'_s18_q3_2==1 | r`i'_s18_q3_1==1
			replace r`i'_s18_q3_7=0 if r`i'_s18_q3_7==.
		}

		foreach var in 	s18_q3_7 s18_q4_2 s18_q10 s18_q1_1 s18_q2_1 s18_q18_1 s18_q18_2 s18_q18_3 s18_q18_4 {
			replace r2_`var'=. if r3_`var'==.
			replace r3_`var'=. if r2_`var'==.
			g diff_`var'=r3_`var'-r2_`var'
		}
		
		local diffs diff_s18_q3_7 diff_s18_q4_2 diff_s18_q10 diff_s18_q1_1 diff_s18_q2_1 diff_s18_q18_1 diff_s18_q18_2 diff_s18_q18_3 diff_s18_q18_4
		
	* estimate impact * 
		eststo clear 
		
		foreach i in `diffs' {
			eststo: noisily reg `i' owl hc [pw=weight], vce(cluster village_code)
			testparm owl hc 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	
		
		xml_tab *_1, save($out/knowledge.xls) append stats(N pvalue_all) title("Knowledge of feeding practices") b sd2 sheet(feed_new_TE) format(SCLR3 NCLR3) keep(owl hc)
		
		foreach var in r2_s18_q3_7 r2_s18_q4_2 r2_s18_q10 r2_s18_q1_1 r2_s18_q2_1 r2_s18_q18_1 r2_s18_q18_2 r2_s18_q18_3 r2_s18_q18_4 r3_s18_q3_7 r3_s18_q4_2 r3_s18_q10 r3_s18_q1_1 r3_s18_q2_1 r3_s18_q18_1 r3_s18_q18_2 r3_s18_q18_3 r3_s18_q18_4 {
			mat `var'=J(3,3,.)
			local c=1
			
			forvalue i=0/2 {
				summ `var' [aw=weight] if treatment==`i'
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'
			mat list `var'
		}
		
		matrix all=r2_s18_q3_7\r3_s18_q3_7\r2_s18_q4_2\r3_s18_q4_2\r2_s18_q10\r3_s18_q10\r2_s18_q1_1\r3_s18_q1_1\r2_s18_q2_1\r3_s18_q2_1\r2_s18_q18_1\r3_s18_q18_1\r2_s18_q18_2\r3_s18_q18_2\r2_s18_q18_3\r3_s18_q18_3\r2_s18_q18_4\r3_s18_q18_4  
		mat colnames all = "Control" "OWL" "HC"
		mat list all

		frmttable using "$out/Knowledge Feeding Women New HH TE", replace sdec(2,2,2) statmat(all) coljust(l;c) ctitles("", Control, OWL, HC)		
		
*******************************************************
*** Health and care knowledge of primary caregivers ***
*******************************************************

* prepare data *
	tokenize data2010 data2012 data2013
	local j=1
	
	forvalue i=1/3 {
		* prepare anthropometry section *
		use "$``j''/R`i'_Section_24", clear
		do "$do/analysis r`i' s24_v1" 
				
		duplicates report hhid idp_child 
		sort hhid idp_mother idp_child
	
		save "$do/r`i's24", replace 
		
		* merge child age in months to kowledge section *
		if `i'!=1 {
			use "$``j''/R`i'_Section_18_Mom", clear
		}
		else {	
			use "$``j''/R`i'_Section_18", clear
		}
		
		sort hhid idp_child 
		merge m:1 hhid idp_child using "$do/r`i's24", keepusing(ch_agemo) keep(mat) nogen
		
		drop if missing(idp_mother)
		
		* add round specific prefix *
		rename * r`i'_*
		
		foreach var in hhid idp_mother idp_child treatment newHH {
			rename r`i'_`var' `var'
		}
		
		save "$do/r`i's18_health", replace 

		local j=`j'+1
		
	}
	
* merge rounds for total effect. merge attrition weights *
	use "$do/r1s18_health", clear
	keep if r1_ch_agemo>=3 & r1_ch_agemo<=12

	merge 1:1 hhid idp_mother idp_child using "$do/r2s18_health", keep (mat) nogen
	merge 1:1 hhid idp_mother idp_child using "$do/r3s18_health", keep (mat) nogen
	merge m:1 hhid using "$dir/data/hh_attrition_weights", keepusing(weight village_code) nogen keep(mas mat)
	
* keep only caregivers with full info *
	foreach var in s18_q27_1 s18_q27_2 s18_q27_3 s18_q27_4 s18_q25_1 s18_q25_11 s18_q25_14 s18_q25_8 s18_q25_4 s18_q25_7 {
		replace r1_`var'=. if r2_`var'==.
		replace r1_`var'=. if r3_`var'==.
		replace r2_`var'=. if r1_`var'==.
		replace r2_`var'=. if r3_`var'==.
		replace r3_`var'=. if r1_`var'==.
		replace r3_`var'=. if r2_`var'==.
	}
	
	******************************************************************
	**** TOTAL EFFECT (2010 - 2013) - Women in old HH   (Panel C) ****	
	******************************************************************
		
	* gen treatment group indicators *
		gen owl=1 if treatment==1
		replace owl=0 if treatment==0 | treatment==2
		lab var owl "OWL group"
		
		gen hc=1 if treatment==2 
		replace hc=0 if treatment==0 | treatment==1
		lab var hc "HC group"

	* generate differences over time *
		foreach var in s18_q27_1 s18_q27_2 s18_q27_3 s18_q27_4 s18_q25_1 s18_q25_11 s18_q25_14 s18_q25_8 s18_q25_4 s18_q25_7 {
			g diff_`var'=r3_`var'-r1_`var'
		}
		
		local diffs diff_s18_q27_1 diff_s18_q27_2 diff_s18_q27_3 diff_s18_q27_4 diff_s18_q25_1 diff_s18_q25_11 diff_s18_q25_14 diff_s18_q25_8  diff_s18_q25_4 diff_s18_q25_7
		
	* estimate impact * 
		eststo clear 
		
		foreach i in `diffs' {
			eststo: noisily reg `i' owl hc [pw=weight], vce(cluster village_code)
			testparm owl hc 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	
		
		xml_tab *_1, save($out/knowledge.xls) append stats(N pvalue_all) title("Knowledge of health practices") b sd2 sheet(health_old_TE) format(SCLR3 NCLR3) keep(owl hc)
		
		foreach var in r1_s18_q27_1 r1_s18_q27_2 r1_s18_q27_3 r1_s18_q27_4 r1_s18_q25_1 r1_s18_q25_11 r1_s18_q25_14 r1_s18_q25_8 r1_s18_q25_2 r1_s18_q25_3 r1_s18_q25_4 r1_s18_q25_7 r3_s18_q27_1 r3_s18_q27_2 r3_s18_q27_3 r3_s18_q27_4 r3_s18_q25_1 r3_s18_q25_11 r3_s18_q25_14 r3_s18_q25_8 r3_s18_q25_2 r3_s18_q25_3 r3_s18_q25_4 r3_s18_q25_7 {
			mat `var'=J(3,3,.)
			local c=1
			
			forvalue i=0/2 {
				summ `var' [aw=weight] if treatment==`i'
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'
			mat list `var'
		}
		
		matrix all=r1_s18_q27_1\r3_s18_q27_1\r1_s18_q27_2\r3_s18_q27_2\r1_s18_q27_3\r3_s18_q27_3\r1_s18_q27_4\r3_s18_q27_4\r1_s18_q25_1\r3_s18_q25_1\r1_s18_q25_11\r3_s18_q25_11\r1_s18_q25_14\r3_s18_q25_14\r1_s18_q25_8\r3_s18_q25_8\r1_s18_q25_2\r3_s18_q25_2\r1_s18_q25_3\r3_s18_q25_3\r1_s18_q25_4\r3_s18_q25_4\r1_s18_q25_7\r3_s18_q25_7 
		mat colnames all = "Control" "OWL" "HC"
		mat list all

		frmttable using "$out/Knowledge Health Women Old HH TE", replace sdec(2,2,2) statmat(all) coljust(l;c) ctitles("", Control, OWL, HC)	
			
			
	*******************************************************************
	**** EARLY EFFECT (2010 - 2012) - Womein in old HH   (Panel A) ****	
	*******************************************************************
		
	* generate differences over time *
		drop diff*
		
		foreach var in s18_q27_1 s18_q27_2 s18_q27_3 s18_q27_4 s18_q25_1 s18_q25_11 s18_q25_14 s18_q25_8 s18_q25_4 s18_q25_7 {
			g diff_`var'=r2_`var'-r1_`var'
		}
		
		local diffs diff_s18_q27_1 diff_s18_q27_2 diff_s18_q27_3 diff_s18_q27_4 diff_s18_q25_1 diff_s18_q25_11 diff_s18_q25_14 diff_s18_q25_8  diff_s18_q25_4 diff_s18_q25_7
		
	* estimate impact * 
		eststo clear 
		
		foreach i in `diffs' {
			eststo: noisily reg `i' owl hc [pw=weight], vce(cluster village_code)
			testparm owl hc 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	
		
		xml_tab *_1, save($out/knowledge.xls) append stats(N pvalue_all) title("Knowledge of health practices") b sd2 sheet(health_old_EE) format(SCLR3 NCLR3) keep(owl hc)
		
		foreach var in r1_s18_q27_1 r1_s18_q27_2 r1_s18_q27_3 r1_s18_q27_4 r1_s18_q25_1 r1_s18_q25_11 r1_s18_q25_14 r1_s18_q25_8 r1_s18_q25_2 r1_s18_q25_3 r1_s18_q25_4 r1_s18_q25_7 r2_s18_q27_1 r2_s18_q27_2 r2_s18_q27_3 r2_s18_q27_4 r2_s18_q25_1 r2_s18_q25_11 r2_s18_q25_14 r2_s18_q25_8 r2_s18_q25_2 r2_s18_q25_3 r2_s18_q25_4 r2_s18_q25_7 {
			mat `var'=J(3,3,.)
			local c=1
			
			forvalue i=0/2 {
				summ `var' [aw=weight] if treatment==`i'
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'
			mat list `var'
		}
		
		matrix all=r1_s18_q27_1\r2_s18_q27_1\r1_s18_q27_2\r2_s18_q27_2\r1_s18_q27_3\r2_s18_q27_3\r1_s18_q27_4\r2_s18_q27_4\r1_s18_q25_1\r2_s18_q25_1\r1_s18_q25_11\r2_s18_q25_11\r1_s18_q25_14\r2_s18_q25_14\r1_s18_q25_8\r2_s18_q25_8\r1_s18_q25_2\r2_s18_q25_2\r1_s18_q25_3\r2_s18_q25_3\r1_s18_q25_4\r2_s18_q25_4\r1_s18_q25_7\r2_s18_q25_7 
		mat colnames all = "Control" "OWL" "HC"
		mat list all

		frmttable using "$out/Knowledge Health Women Old HH EE", replace sdec(2,2,2) statmat(all) coljust(l;c) ctitles("", Control, OWL, HC)	
		
	***************************************************************
	**** LATER EFFECT (2012-2013) - Women in old HH  (Panel B) ****	
	***************************************************************

	* generate differences over time *
		drop diff*
		
		foreach var in s18_q27_1 s18_q27_2 s18_q27_3 s18_q27_4 s18_q25_1 s18_q25_11 s18_q25_14 s18_q25_8 s18_q25_4 s18_q25_7 {
			g diff_`var'=r3_`var'-r2_`var'
		}
		
		local diffs diff_s18_q27_1 diff_s18_q27_2 diff_s18_q27_3 diff_s18_q27_4 diff_s18_q25_1 diff_s18_q25_11 diff_s18_q25_14 diff_s18_q25_8  diff_s18_q25_4 diff_s18_q25_7
		
	* estimate impact * 
		eststo clear 
		
		foreach i in `diffs' {
			eststo: noisily reg `i' owl hc [pw=weight], vce(cluster village_code)
			testparm owl hc 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	
		
		xml_tab *_1, save($out/knowledge.xls) append stats(N pvalue_all) title("Knowledge of health practices") b sd2 sheet(health_old_LE) format(SCLR3 NCLR3) keep(owl hc)
		
		foreach var in r2_s18_q27_1 r2_s18_q27_2 r2_s18_q27_3 r2_s18_q27_4 r2_s18_q25_1 r2_s18_q25_11 r2_s18_q25_14 r2_s18_q25_8 r2_s18_q25_2 r2_s18_q25_3 r2_s18_q25_4 r2_s18_q25_7 r3_s18_q27_1 r3_s18_q27_2 r3_s18_q27_3 r3_s18_q27_4 r3_s18_q25_1 r3_s18_q25_11 r3_s18_q25_14 r3_s18_q25_8 r3_s18_q25_2 r3_s18_q25_3 r3_s18_q25_4 r3_s18_q25_7  {
			mat `var'=J(3,3,.)
			local c=1
			
			forvalue i=0/2 {
				summ `var' [aw=weight] if treatment==`i'
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'
			mat list `var'
		}
		
		matrix all=r2_s18_q27_1\r3_s18_q27_1\r2_s18_q27_2\r3_s18_q27_2\r2_s18_q27_3\r3_s18_q27_3\r2_s18_q27_4\r3_s18_q27_4\r2_s18_q25_1\r3_s18_q25_1\r2_s18_q25_11\r3_s18_q25_11\r2_s18_q25_14\r3_s18_q25_14\r2_s18_q25_8\r3_s18_q25_8\r2_s18_q25_2\r3_s18_q25_2\r2_s18_q25_3\r3_s18_q25_3\r2_s18_q25_4\r3_s18_q25_4\r2_s18_q25_7\r3_s18_q25_7 
		mat colnames all = "Control" "OWL" "HC"
		mat list all

		frmttable using "$out/Knowledge Health Women Old HH LE", replace sdec(2,2,2) statmat(all) coljust(l;c) ctitles("", Control, OWL, HC)	


* merge rounds for total effect. merge attrition weights *
	use "$do/r2s18_health", clear
	keep if newHH==1 & r2_ch_agemo>=3 & r2_ch_agemo<=12

	merge 1:1 hhid idp_mother idp_child using "$do/r3s18_health", keep (mat) nogen
	merge m:1 hhid using "$dir/data/hh_attrition_weights", keepusing(weight village_code) nogen keep(mas mat)
	
* keep only caregivers with full info *
		foreach var in s18_q27_1 s18_q27_2 s18_q27_3 s18_q27_4 s18_q25_1 s18_q25_11 s18_q25_14 s18_q25_8 s18_q25_4 s18_q25_7 {
			replace r2_`var'=. if r3_`var'==.
			replace r3_`var'=. if r2_`var'==.
		}

	********************************************************************
	**** TOTAL EFFECT (2012 - 2013) - Women in newHH only (Panel D) ****	
	********************************************************************
		
	* gen treatment group indicators *
		gen owl=1 if treatment==1
		replace owl=0 if treatment==0 | treatment==2
		lab var owl "OWL group"
		
		gen hc=1 if treatment==2 
		replace hc=0 if treatment==0 | treatment==1
		lab var hc "HC group"

	* generate differences over time *
		foreach var in s18_q27_1 s18_q27_2 s18_q27_3 s18_q27_4 s18_q25_1 s18_q25_11 s18_q25_14 s18_q25_8 s18_q25_4 s18_q25_7 {
			g diff_`var'=r3_`var'-r2_`var'
		}
		
		local diffs diff_s18_q27_1 diff_s18_q27_2 diff_s18_q27_3 diff_s18_q27_4 diff_s18_q25_1 diff_s18_q25_11 diff_s18_q25_14 diff_s18_q25_8  diff_s18_q25_4 diff_s18_q25_7
		
	* estimate impact * 
		eststo clear 
		
		foreach i in `diffs' {
			eststo: noisily reg `i' owl hc [pw=weight], vce(cluster village_code)
			testparm owl hc 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	
		
		xml_tab *_1, save($out/knowledge.xls) append stats(N pvalue_all) title("Knowledge of health practices") b sd2 sheet(health_new_TE) format(SCLR3 NCLR3) keep(owl hc)
		
		foreach var in r2_s18_q27_1 r2_s18_q27_2 r2_s18_q27_3 r2_s18_q27_4 r2_s18_q25_1 r2_s18_q25_11 r2_s18_q25_14 r2_s18_q25_8 r2_s18_q25_2 r2_s18_q25_3 r2_s18_q25_4 r2_s18_q25_7 r3_s18_q27_1 r3_s18_q27_2 r3_s18_q27_3 r3_s18_q27_4 r3_s18_q25_1 r3_s18_q25_11 r3_s18_q25_14 r3_s18_q25_8 r3_s18_q25_2 r3_s18_q25_3 r3_s18_q25_4 r3_s18_q25_7  {
			mat `var'=J(3,3,.)
			local c=1
			
			forvalue i=0/2 {
				summ `var' [aw=weight] if treatment==`i'
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'
			mat list `var'
		}
		
		matrix all=r2_s18_q27_1\r3_s18_q27_1\r2_s18_q27_2\r3_s18_q27_2\r2_s18_q27_3\r3_s18_q27_3\r2_s18_q27_4\r3_s18_q27_4\r2_s18_q25_1\r3_s18_q25_1\r2_s18_q25_11\r3_s18_q25_11\r2_s18_q25_14\r3_s18_q25_14\r2_s18_q25_8\r3_s18_q25_8\r2_s18_q25_2\r3_s18_q25_2\r2_s18_q25_3\r3_s18_q25_3\r2_s18_q25_4\r3_s18_q25_4\r2_s18_q25_7\r3_s18_q25_7 
		mat colnames all = "Control" "OWL" "HC"
		mat list all

		frmttable using "$out/Knowledge Health Women New HH TE", replace sdec(2,2,2) statmat(all) coljust(l;c) ctitles("", Control, OWL, HC)	

*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
*	Infant and young child feeding practices 		*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
	
* open appended data *
	use "$datam/iycf_impact", clear
	
* identify new children in new hh *
	g group1=1 if newHH==0 & (time==1 | time==0)
	g group2=1 if newHH==1 | (newHH==0 & time==0)

	lab var group1 "Old HH, BL and EL"
	lab var group2 "Old HH, BL and new HH EL"
	
* rename and relabel vars *
	lab var mo_age "Mother's age (in years)"
	
* variables of interest *
	local vars bfeed early bf_exclu bf_pred bottle intro

* verify indicators *
	foreach var in `vars' {
		summ ch_ageda if `var'!=.
		replace `var'=`var'*100
	}
	
* estimate impact - old HH 3-12m at BL or EL *
	eststo clear 
	
	foreach var in `vars' {
		xi: xtreg `var' i.treatment*i.time mo_age if group1==1, fe i(village_code) vce(cluster village_code)
		testparm _ItreXtim_1_1 _ItreXtim_2_1
		local pvalue=r(p)
		eststo `var'_1, addscalars(pvalue `pvalue')
	}
	
	#d; 
		xml_tab *_1, save($out/iycf.xls) replace stats(N pvalue) b sd2 sheet(oldHH) 
		title("Infant and young child feeding practices among caregivers of children 3-12 months of age at baseline or endline in old households") 
		format(SCLR1 NCLR1) drop(_Itreatment_1 _Itreatment_2 _cons)
		font("Times New Roman" 12)
		note("Comparison is to a control group that did not receive any program services. All estimates controlled for mother's age, clustering, and attrition. All values are coefficient (SE).  *** p<0.01, ** p<0.05, * p<0.10");
	#d cr
	
*** estimate impact - old H 3-12m at BL and new HH 3-12 m at EL *** 
	eststo clear 
	
	foreach var in `vars' {
		xi: xtreg `var' i.treatment*i.time mo_age if group2==1, fe i(village_code) vce(cluster village_code)
		testparm _ItreXtim_1_1 _ItreXtim_2_1
		local pvalue=r(p)
		eststo `var'_1, addscalars(pvalue `pvalue')
	}
	
	#d; 
		xml_tab *_1, save($out/iycf.xls) append stats(N pvalue) b sd2 sheet(newHH) 
		title("Infant and young child feeding practices among caregivers of children 3-12 months at baseline in old households or 3-12 m at endline in new households") 
		format(SCLR1 NCLR1) drop(_Itreatment_1 _Itreatment_2 _cons)
		font("Times New Roman" 12)
		note("Comparison is to a control group that did not receive any program services. All estimates controlled for mother's age, clustering, and attrition. All values are coefficient (SE).  *** p<0.01, ** p<0.05, * p<0.10");
	#d cr 	
		
		
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
* Nutrition and Anemia Outcomes from Agricultural and BCC Interventions	*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*

//-----------------------------------------------------------------------------//
// 				Group 1 - Children 3-12 months at BL old HH					   //		
//-----------------------------------------------------------------------------//

	use "$datam/Section 24 Group 1", clear
	
	duplicates report hhid idp_child // 1068 obs 
	
* keep only relevant vars * 
	*drop *_ageda birthdate *_intdate *_rand s24_q2 s24_q1 *_age6mo *_age3mo *_age1mo  
	
	forvalue i=1/3 {
		rename r`i'_s24 r`i'_hemoglobin
		}
	
	rename idp_child idp
	
* keep only valid Z scores 	
	foreach var in r1_ch_whz06 r1_ch_waz06 r2_ch_waz06 r2_ch_whz06 r3_ch_waz06 r3_ch_whz06 {
*		g flag`var'=1 if abs(`var')>6 
		replace `var'=. if abs(`var')>6 
	}
	
	replace r1_hemoglobin=. if r2_hemoglobin==. | r3_hemoglobin==.
	replace r2_hemoglobin=. if r1_hemoglobin==. | r3_hemoglobin==.
	replace r3_hemoglobin=. if r1_hemoglobin==. | r2_hemoglobin==.
	
	forvalue i=1/3 {
		replace r`i'_anemic=. if r`i'_hemoglobin==. 
		replace r`i'_anemic_severe=. if r`i'_hemoglobin==.
		replace r`i'_underweight=. if r`i'_ch_waz06==.
		replace r`i'_wasting=. if r`i'_ch_whz06==. 
	}	
		
	
* merge in child attrition status and weights *
	sort hhid idp
	
	merge 1:1 hhid idp using "$dir/data/child_attrition", keepusing (attrition) keep(mat) nogen
	merge 1:1 hhid idp using "$dir/data/child_attrition_weights", keepusing (weight district village_code) keep(mat) nogen
	
* label vars * 
	lab var district "District" 
	lab var weight "Attrition weight (inverse of probability to attrite)"
	
* gen treatment group indicators *
	gen owl=1 if treatment==1
	replace owl=0 if treatment==0 | treatment==2
	lab var owl "OWL group"
	
	gen hc=1 if treatment==2 
	replace hc=0 if treatment==0 | treatment==1
	lab var hc "HC group"

	****************************************************************************
	**** TOTAL EFFECT (2010 - 2013) - GROUP 1, 3-12 M AT BASELINE (Panel C) ****	
	****************************************************************************

	* genera differences over time *
		foreach var in hemoglobin anemic anemic_severe ch_waz06 ch_whz06 underweight wasting {
			g diff_`var'=r3_`var'-r1_`var'
			}
		
		local diffs diff_hemoglobin diff_anemic diff_anemic_severe diff_ch_waz06 diff_ch_whz06 diff_underweight diff_wasting

		replace diff_hemoglobin=. if r1_hemoglobin==. | r3_hemoglobin==.
		replace diff_anemic_severe=. if diff_hemoglobin==. | r3_hemoglobin==.
		replace diff_anemic=. if diff_hemoglobin==. | r3_hemoglobin==.
		replace diff_wasting=. if diff_ch_whz06==.
		replace diff_underweight=. if diff_ch_waz06==.
		
	* make table for antho impacts *
		summ r1_ch_agemo 
				
	* age 3-12 m
		eststo clear 
		
		foreach i in `diffs' {
			eststo: noisily reg `i' owl hc r1_ch_agemo ch_sex [pw=weight] if r1_ch_agemo<12, vce(cluster village_code)
			testparm owl hc 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	
		
		xml_tab *_1, save($out/anthro.xls) replace stats(N pvalue_all) title("Anthro Impact") b sd2 sheet(old_hh_3to12bl_TE) format(SCLR3 NCLR3) keep(owl hc)
		
		foreach var in r1_hemoglobin r1_anemic r1_anemic_severe r1_ch_waz06 r1_underweight r1_ch_whz06 r1_wasting r3_hemoglobin r3_anemic r3_anemic_severe r3_ch_waz06 r3_underweight r3_ch_whz06 r3_wasting {
			mat `var'=J(3,3,.)
			local c=1
			
			forvalue i=0/2 {
				summ `var' [aw=weight] if treatment==`i' & r1_ch_agemo<12
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'
			mat list `var'
		}
		
		matrix all=r1_hemoglobin\r3_hemoglobin\r1_anemic\r3_anemic\r1_anemic_severe\r3_anemic_severe\r1_ch_waz06\r3_ch_waz06\r1_underweight\r3_underweight\r1_ch_whz06\r3_ch_whz06\r1_wasting\r3_wasting 
		mat colnames all = "Control" "OWL" "HC"
		mat list all

		frmttable using "$out/Antho Children 3-12 mo BL Old HH TE", replace sdec(2,2,2) statmat(all) coljust(l;c) ctitles("", Control, OWL, HC)	
			
	* age 3-6 m *		
		eststo clear 
		
		foreach i in `diffs' {
			eststo: noisily reg `i' owl hc r1_ch_agemo ch_sex [pw=weight]if r1_ch_agemo<6, vce(cluster village_code)
			testparm owl hc 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	
		
		xml_tab *_1, save($out/anthro.xls) append stats(N pvalue_all) title("Anthro Impact 6m") b sd2 sheet(old_hh_3to12bl_TE_6mo) format(SCLR3 NCLR3) keep(owl hc)
		
		foreach var in r1_hemoglobin r1_anemic r1_anemic_severe r1_ch_waz06 r1_ch_whz06 r3_hemoglobin r3_anemic r3_anemic_severe r3_ch_waz06 r3_ch_whz06 {
			mat `var'=J(3,3,.)
			local c=1
			
			forvalue i=0/2 {
				summ `var' [aw=weight] if treatment==`i' & r1_ch_agemo<6
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'
			mat list `var'
		}
		
		matrix all_6m=r1_hemoglobin\r3_hemoglobin\r1_anemic\r3_anemic\r1_anemic_severe\r3_anemic_severe
		mat colnames all = "Control" "OWL" "HC"
		mat list all
		
		frmttable using "$out/Anthro Children 3-12 mo BL Old HH TE", append sdec(2,2,2) statmat(all_6m) title("3-6 months") coljust(l;c) ctitles("", Control, OWL, HC)	

	****************************************************************************
	**** EARLY EFFECT (2010 - 2012) - GROUP 1, 3-12 M AT BASELINE (Panel A) ****	
	****************************************************************************

	* genera differences over time *
		drop diff*
		
		foreach var in hemoglobin anemic anemic_severe ch_waz06 ch_whz06 underweight wasting {
			g diff_`var'=r2_`var'-r1_`var'
			}
		
		local diffs diff_hemoglobin diff_anemic diff_anemic_severe diff_ch_waz06 diff_ch_whz06 diff_underweight diff_wasting

		replace diff_hemoglobin=. if r1_hemoglobin==. | r2_hemoglobin==.
		replace diff_anemic_severe=. if diff_hemoglobin==. | r2_hemoglobin==.
		replace diff_anemic=. if diff_hemoglobin==. | r2_hemoglobin==.
		replace diff_wasting=. if diff_ch_whz06==.
		replace diff_underweight=. if diff_ch_waz06==.
		
	* make table for antho impacts *		
		summ r1_ch_agemo 
				
	* age 3-12 m
		eststo clear 
		
		foreach i in `diffs' {
			eststo: noisily reg `i' owl hc r1_ch_agemo ch_sex [pw=weight] if r1_ch_agemo<12, vce(cluster village_code)
			testparm owl hc 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	
		
		xml_tab *_1, save($out/anthro.xls) append stats(N pvalue_all) title("Anthro Impact") b sd2 sheet(old_hh_3to12bl_EE) format(SCLR3 NCLR3) keep(owl hc)
		
		foreach var in r1_hemoglobin r1_anemic r1_anemic_severe r1_ch_waz06 r1_underweight r1_ch_whz06 r1_wasting r2_hemoglobin r2_anemic r2_anemic_severe r2_ch_waz06 r2_underweight r2_ch_whz06 r2_wasting {
			mat `var'=J(3,3,.)
			local c=1
			
			forvalue i=0/2 {
				summ `var' [aw=weight] if treatment==`i' & r1_ch_agemo<12
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'
			mat list `var'
		}
		
		matrix all=r1_hemoglobin\r2_hemoglobin\r1_anemic\r2_anemic\r1_anemic_severe\r2_anemic_severe\r1_ch_waz06\r2_ch_waz06\r1_underweight\r2_underweight\r1_ch_whz06\r2_ch_whz06\r1_wasting\r2_wasting 
		mat colnames all = "Control" "OWL" "HC"
		mat list all

		frmttable using "$out/Anthro Children 3-12 mo BL Old HH EE", replace sdec(2,2,2) statmat(all) coljust(l;c) ctitles("", Control, OWL, HC)	
			
	* age 3-6 m *		
		eststo clear 
		
		foreach i in `diffs' {
			eststo: noisily reg `i' owl hc r1_ch_agemo ch_sex [pw=weight]if r1_ch_agemo<6, vce(cluster village_code)
			testparm owl hc 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	
		
		xml_tab *_1, save($out/anthro.xls) append stats(N pvalue_all) title("Anthro Impact 6m") b sd2 sheet(old_hh_3to12bl_EE_6mo) format(SCLR3 NCLR3) keep(owl hc)
		
		foreach var in r1_hemoglobin r1_anemic r1_anemic_severe r1_ch_waz06 r1_ch_whz06 r2_hemoglobin r2_anemic r2_anemic_severe r2_ch_waz06 r2_ch_whz06 {
			mat `var'=J(3,3,.)
			local c=1
			
			forvalue i=0/2 {
				summ `var' [aw=weight] if treatment==`i' & r1_ch_agemo<6
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'
			mat list `var'
		}
		
		matrix all_6m=r1_hemoglobin\r2_hemoglobin\r1_anemic\r2_anemic\r1_anemic_severe\r2_anemic_severe
		mat colnames all = "Control" "OWL" "HC"
		mat list all
		
		frmttable using "$out/Anthro Children 3-12 mo BL Old HH EE", append sdec(2,2,2) statmat(all_6m) title("3-60 months") coljust(l;c) ctitles("", Control, OWL, HC)	
		
	**************************************************************************
	**** LATER EFFECT (2012-2013) - GROUP 1, 3-12 M AT BASELINE (Panel B) ****	
	**************************************************************************

	* genera differences over time *		
		drop diff_*
		
		foreach var in hemoglobin anemic anemic_severe ch_waz06 ch_whz06 underweight wasting {
			g diff_`var'=r3_`var'-r2_`var'
			}
		
		local diffs diff_hemoglobin diff_anemic diff_anemic_severe diff_ch_waz06 diff_ch_whz06 diff_underweight diff_wasting

		replace diff_hemoglobin=. if r2_hemoglobin==. | r3_hemoglobin==.
		replace diff_anemic_severe=. if diff_hemoglobin==. | r3_hemoglobin==.
		replace diff_anemic=. if diff_hemoglobin==. | r3_hemoglobin==.
		replace diff_wasting=. if diff_ch_whz06==.
		replace diff_underweight=. if diff_ch_waz06==.

	* make table for antho impacts *		
		summ r1_ch_agemo
			
	* age 3-12 m
		eststo clear 
		
		foreach i in `diffs' {
			eststo: noisily reg `i' owl hc r1_ch_agemo ch_sex [pw=weight] if r1_ch_agemo<12, vce(cluster village_code)
			testparm owl hc 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	
		
		xml_tab *_1, save($out/anthro.xls) append stats(N pvalue_all) title("Anthro Impact") b sd2 sheet(old_hh_3to12bl_LE) format(SCLR3 NCLR3) keep(owl hc)
		
		foreach var in r2_hemoglobin r2_anemic r2_anemic_severe r2_ch_waz06 r2_underweight r2_ch_whz06 r2_wasting r3_hemoglobin r3_anemic r3_anemic_severe r3_ch_waz06 r3_underweight r3_ch_whz06 r3_wasting {
			mat `var'=J(3,3,.)
			local c=1
			
			forvalue i=0/2 {
				summ `var' [aw=weight] if treatment==`i' & r1_ch_agemo<12
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'
			mat list `var'
		}
		
		matrix all=r2_hemoglobin\r3_hemoglobin\r2_anemic\r3_anemic\r2_anemic_severe\r3_anemic_severe\r2_ch_waz06\r3_ch_waz06\r2_underweight\r3_underweight\r2_ch_whz06\r3_ch_whz06\r2_wasting\r3_wasting 
		mat colnames all = "Control" "OWL" "HC"
		mat list all

		frmttable using "$out/Anthro Children 3-12 mo BL Old HH LE", replace sdec(2,2,2) statmat(all) coljust(l;c) ctitles("", Control, OWL, HC)	
			
	* age 3-6 m *		
		eststo clear 
		
		foreach i in `diffs' {
			eststo: noisily reg `i' owl hc r1_ch_agemo ch_sex [pw=weight]if r1_ch_agemo<6, vce(cluster village_code)
			testparm owl hc 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	
		
		xml_tab *_1, save($out/anthro.xls) append stats(N pvalue_all) title("Anthro Impact 6m") b sd2 sheet(old_hh_3to12bl_LE_6mo) format(SCLR3 NCLR3) keep(owl hc)
		
		foreach var in r2_hemoglobin r2_anemic r2_anemic_severe r2_ch_waz06 r2_ch_whz06 r3_hemoglobin r3_anemic r3_anemic_severe r3_ch_waz06 r3_ch_whz06 {
			mat `var'=J(3,3,.)
			local c=1
			
			forvalue i=0/2 {
				summ `var' [aw=weight] if treatment==`i' & r1_ch_agemo<6
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'
			mat list `var'
		}
		
		matrix all_6m=r2_hemoglobin\r3_hemoglobin\r2_anemic\r3_anemic\r2_anemic_severe\r3_anemic_severe
		mat colnames all = "Control" "OWL" "HC"
		mat list all
		
		frmttable using "$out/Anthro Children 3-12 mo BL Old HH LE", append sdec(2,2,2) statmat(all_6m) title("3-6 months") coljust(l;c) ctitles("", Control, OWL, HC)	

//-----------------------------------------------------------------------------//
// 				Group 2 - Children 3-12 months at EL old HH					   //		
//-----------------------------------------------------------------------------//

* prepare data *
	use "$datam/Section 24 Group 2", clear
		
	duplicates report hhid idp_child // 276 obs 
		
* keep only relevant vars * 
	drop *_ageda birthdate *_intdate *_rand *_age6mo *_age3mo *_age1mo s24_q1 FPrimary Instan*
		
	forvalue i=2/3 {
		rename r`i'_s24 r`i'_hemoglobin
		}
	
	rename idp_child idp
		
* keep only valid Z scores *	
	foreach var in r2_ch_waz06 r2_ch_whz06 r3_ch_waz06 r3_ch_whz06 {
		replace `var'=. if abs(`var')>6 
	}
	
	replace r2_hemoglobin=. if r3_hemoglobin==.
	replace r3_hemoglobin=. if r2_hemoglobin==.
	
	forvalue i=2/3 {
		replace r`i'_hemoglobin=. if r`i'_hemoglobin<3
		replace r`i'_anemic=. if r`i'_hemoglobin==. 
		replace r`i'_anemic_severe=. if r`i'_hemoglobin==.
		replace r`i'_underweight=. if r`i'_ch_waz06==.
		replace r`i'_wasting=. if r`i'_ch_whz06==. 
	}	

* merge in child attrition status and weights *
	sort hhid idp
	merge 1:1 hhid idp using "$dir/data/child_attrition", keepusing (attrition) keep(mat) nogen
	merge 1:1 hhid idp using "$dir/data/child_attrition_weights", keepusing (weight district village_code) keep(mat) nogen
		
* label vars * 
	lab var district "District" 
	lab var weight "Attrition weight (inverse of probability to attrite)"
	
* gen treatment group indicators *
	gen owl=1 if treatment==1
	replace owl=0 if treatment==0 | treatment==2
	lab var owl "OWL group"
	
	gen hc=1 if treatment==2 
	replace hc=0 if treatment==0 | treatment==1
	lab var hc "HC group"
	
	****************************************************************************************
	**** TOTAL EFFECT (2012 - 2013) - GROUP 2 (B), 3-12 M AT ENDLINE, OLD HH  (Panel D) ****	
	****************************************************************************************

	* genera differences over time *		
		foreach var in hemoglobin anemic anemic_severe ch_waz06 ch_whz06 underweight wasting {
			g diff_`var'=r3_`var'-r2_`var'
			}
		
		local diffs diff_hemoglobin diff_anemic diff_anemic_severe diff_ch_waz06 diff_ch_whz06 diff_underweight diff_wasting

	* make table for antho impacts *	
		summ r2_ch_agemo  
		count if r2_ch_agemo>3 & r2_ch_agemo<12 //276 obs
		
	* age 3-12 m
		eststo clear 
		
		foreach i in `diffs' {
			eststo: noisily reg `i' owl hc r2_ch_agemo ch_sex [pw=weight], vce(cluster village_code)
			testparm owl hc 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	
		
		xml_tab *_1, save($out/anthro.xls) append stats(N pvalue_all) title("Anthro Impact") b sd2 sheet(old_hh_3to12el_TE) format(SCLR3 NCLR3) keep(owl hc)
		
		foreach var in r2_hemoglobin r2_anemic r2_anemic_severe r2_ch_waz06 r2_underweight r2_ch_whz06 r2_wasting r3_hemoglobin r3_anemic r3_anemic_severe r3_ch_waz06 r3_underweight r3_ch_whz06 r3_wasting {
			mat `var'=J(3,3,.)
			local c=1
			
			forvalue i=0/2 {
				summ `var' [aw=weight] if treatment==`i' 
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'
			mat list `var'
		}
		
		matrix all=r2_hemoglobin\r3_hemoglobin\r2_anemic\r3_anemic\r2_anemic_severe\r3_anemic_severe\r2_ch_waz06\r3_ch_waz06\r2_underweight\r3_underweight\r2_ch_whz06\r3_ch_whz06\r2_wasting\r3_wasting 
		mat colnames all = "Control" "OWL" "HC"
		mat list all

		frmttable using "$out/Anthro Children 3-12 mo EL Old HH TE", replace sdec(2,2,2) statmat(all) coljust(l;c) ctitles("", Control, OWL, HC)	
			
	* age 3-6 m *
		eststo clear 
		
		foreach i in `diffs' {
			eststo: noisily reg `i' owl hc r2_ch_agemo ch_sex [pw=weight] if r2_ch_agemo<6, vce(cluster village_code)
			testparm owl hc 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	
		
		xml_tab *_1, save($out/anthro.xls) append stats(N pvalue_all) title("Anthro Impact 6m") b sd2 sheet(old_hh_3to12el_TE_6mo) format(SCLR3 NCLR3) keep(owl hc)
		
		foreach var in r2_hemoglobin r2_anemic r2_anemic_severe r2_ch_waz06 r2_ch_whz06 r3_hemoglobin r3_anemic r3_anemic_severe r3_ch_waz06 r3_ch_whz06 {
			mat `var'=J(3,3,.)
			local c=1
			
			forvalue i=0/2 {
				summ `var' [aw=weight] if treatment==`i' & r2_ch_agemo<6
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'
			mat list `var'
		}
		
		matrix all_6m=r2_hemoglobin\r3_hemoglobin\r2_anemic\r3_anemic\r2_anemic_severe\r3_anemic_severe
		mat colnames all = "Control" "OWL" "HC"
		mat list all_6m

		frmttable using "$out/Anthro Children 3-12 mo EL Old HH TE", append sdec(2,2,2) title("3-6 months") statmat(all_6m) coljust(l;c) ctitles("", Control, OWL, HC)	
	
//-----------------------------------------------------------------------------//
// 				Group 3 - Children 3-12 months at EL new HH					   //		
//-----------------------------------------------------------------------------//

* prepare dataset *
	use "$datam/Section 24 Group 3", clear
	
	duplicates report hhid idp_child // 1121 obs 
	
* keep only relevant vars * 	
	drop *_ageda birthdate *_intdate *_rand *_age6mo *_age3mo *_age1mo  
	
	forvalue i=2/3 {
		rename r`i'_s24 r`i'_hemoglobin
		}
	
	rename idp_child idp
	
* keep only valid Z scores *	
	foreach var in r2_ch_waz06 r2_ch_whz06 r3_ch_waz06 r3_ch_whz06 {
		replace `var'=. if abs(`var')>6 
	}
	
	replace r2_hemoglobin=. if r3_hemoglobin==.
	replace r3_hemoglobin=. if r2_hemoglobin==.
	
	forvalue i=2/3 {
		replace r`i'_anemic=. if r`i'_hemoglobin==. 
		replace r`i'_anemic_severe=. if r`i'_hemoglobin==.
		replace r`i'_underweight=. if r`i'_ch_waz06==.
		replace r`i'_wasting=. if r`i'_ch_whz06==. 
	}	

* merge in child attrition status and weights *
	sort hhid idp
	merge 1:1 hhid idp using "$dir/data/child_attrition", keepusing (attrition) keep(mat) nogen
	merge 1:1 hhid idp using "$dir/data/child_attrition_weights", keepusing (weight district village_code) keep(mat) nogen
	
* label vars * 
	
	lab var district "District" 
	lab var weight "Attrition weight (inverse of probability to attrite)"
	
* gen treatment group indicators *
	gen owl=1 if treatment==1
	replace owl=0 if treatment==0 | treatment==2
	lab var owl "OWL group"
	
	gen hc=1 if treatment==2 
	replace hc=0 if treatment==0 | treatment==1
	lab var hc "HC group"
	
	***********************************************************************************
	**** TOTAL EFFECT (2012 - 2013) - GROUP 3, 3-12 M AT ENDLINE  NEW HH (Panel E) ****	
	***********************************************************************************

	* genera differences over time *		
		foreach var in hemoglobin anemic anemic_severe ch_waz06 ch_whz06 underweight wasting {
			g diff_`var'=r3_`var'-r2_`var'
			}
		
		local diffs diff_hemoglobin diff_anemic diff_anemic_severe diff_ch_waz06 diff_ch_whz06 diff_underweight diff_wasting
		
	* make table for antho impacts *		
		summ r2_ch_agemo  
		count if r2_ch_agemo>3 & r2_ch_agemo<12 //684 obs
			
	* age 3-12 m
		eststo clear 
		
		foreach i in `diffs' {
			eststo: noisily reg `i' owl hc r2_ch_agemo ch_sex [pw=weight] if r2_ch_agemo<12 & r2_ch_agemo>3, vce(cluster village_code)
			testparm owl hc 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}
		
		xml_tab *_1, save($out/anthro.xls) append stats(N pvalue_all) title("Anthro Impact") b sd2 sheet(new_hh_3to12el_TE) format(SCLR3 NCLR3) keep(owl hc)
		
		foreach var in r2_hemoglobin r2_anemic r2_anemic_severe r2_ch_waz06 r2_underweight r2_ch_whz06 r2_wasting r3_hemoglobin r3_anemic r3_anemic_severe r3_ch_waz06 r3_underweight r3_ch_whz06 r3_wasting {
			mat `var'=J(3,3,.)
			local c=1
			
			forvalue i=0/2 {
				summ `var' [aw=weight] if treatment==`i' & r2_ch_agemo<12 & r2_ch_agemo>3
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'
			mat list `var'
		}
		
		matrix all=r2_hemoglobin\r3_hemoglobin\r2_anemic\r3_anemic\r2_anemic_severe\r3_anemic_severe\r2_ch_waz06\r3_ch_waz06\r2_underweight\r3_underweight\r2_ch_whz06\r3_ch_whz06\r2_wasting\r3_wasting 
		mat colnames all = "Control" "OWL" "HC"
		mat list all

		frmttable using "$out/Anthro Children 3-12 mo EL New HH TE", replace sdec(2,2,2) statmat(all) coljust(l;c) ctitles("", Control, OWL, HC)	
			
	* age 3-6 m *		
		eststo clear 
		
		foreach i in `diffs' {
			eststo: noisily reg `i' owl hc r2_ch_agemo ch_sex [pw=weight] if r2_ch_agemo<6 & r2_ch_agemo>3, vce(cluster village_code)
			testparm owl hc 
			local pvalue_all=r(p)
			eststo `i'_1, addscalars(pvalue_all `pvalue_all')
		}	
		
		xml_tab *_1, save($out/anthro.xls) append stats(N pvalue_all) title("Anthro Impact 6m") b sd2 sheet(new_hh_3to12el_TE_6mo) format(SCLR3 NCLR3) keep(owl hc)
		
		foreach var in r2_hemoglobin r2_anemic r2_anemic_severe r2_ch_waz06 r2_ch_whz06 r3_hemoglobin r3_anemic r3_anemic_severe r3_ch_waz06 r3_ch_whz06 {
			mat `var'=J(3,3,.)
			local c=1
			
			forvalue i=0/2 {
				summ `var' [aw=weight] if treatment==`i' & r2_ch_agemo<6 & r2_ch_agemo>3
				matrix `var'[1,`c']=r(N)
				matrix `var'[2,`c']=r(mean)
				matrix `var'[3,`c']=r(sd)
				local c=`c'+1
			}
			
			mat rowname `var' = N`var' M`var' SD`var'
			mat list `var'
		}
		
		matrix all_6m=r2_hemoglobin\r3_hemoglobin\r2_anemic\r3_anemic\r2_anemic_severe\r3_anemic_severe
		mat colnames all = "Control" "OWL" "HC"
		mat list all_6m
		
		frmttable using "$out/Anthro Children 3-12 mo EL New HH TE", append sdec(2,2,2) statmat(all_6m) title("3-6 months") coljust(l;c) ctitles("", Control, OWL, HC)	
		
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
*	Cross sectional impacts 3-12 M at BASELINE OR ENDLINE OLD HH 	*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*

	***********************
	**** ANTHROPOMETRY ****	
	***********************

* open appended data **
	use "$datam/anthro_impact_crossect", clear
	
* identify new children in new hh *
	g group1=1 if newHH==0 & (time==1 | time==0)
	g group2=1 if newHH==1 | (newHH==0 & time==0)

	lab var group1 "Old HH, BL and EL"
	lab var group2 "Old HH, BL and new HH EL"
	
* variables of interest *
	rename s24_q9 hemoglobin
	local vars hemoglobin anemic anemic_severe ch_waz06 ch_whz06 underweight wasting
	
* verify indicators *
	replace anemic=. if hemoglobin==. 
	replace anemic_severe=. if hemoglobin==.
	replace underweight=. if ch_waz06==.
	replace wasting=. if ch_whz06==. 
/*	
	foreach var of varlist anemic- wasting {
		replace `var'=`var'*100
	}
*/	

* estimate impact - old HH 3-12m at BL or EL *
	eststo clear 
	
	foreach var in `vars' {
		xi: xtreg `var' i.treatment*i.time ch_agemo ch_sex if group1==1, fe i(village_code) vce(cluster village_code)
		testparm _ItreXtim_1_1 _ItreXtim_2_1
		local pvalue=r(p)
		eststo `var'_1, addscalars(pvalue `pvalue')
	}
	
	#d; 
		xml_tab *_1, save($out/anthro_impact_crosssect.xls) replace stats(N pvalue) b sd2 sheet(oldHH) 
		title("Anemia and anthropomentry of children 3-12 months of age at baseline or endline in old households") 
		format(SCLR1 NCLR1) drop(_Itreatment_1 _Itreatment_2 _cons)
		font("Times New Roman" 12)
		note("Comparison is to a control group that did not receive any program services. All estimates controlled for child's age and sex, clustering, and attrition. All values are coefficient (SE).  *** p<0.01, ** p<0.05, * p<0.10");
	#d cr
			
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
*	Cross sectional impacts 3-12 M at BASELINE AND ENDLINE OLD HH 	*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*

	***********************
	**** ANTHROPOMETRY ****	
	***********************

* open appended data **
	use "$datam/anthro_impact_3to12_samehh", clear
	
* variables of interest *
	rename s24_q9 hemoglobin
	local vars hemoglobin anemic anemic_severe ch_waz06 ch_whz06 underweight wasting
	
* verify indicators *
	replace anemic=. if hemoglobin==. 
	replace anemic_severe=. if hemoglobin==.
	replace underweight=. if ch_waz06==.
	replace wasting=. if ch_whz06==. 
	
* estimate impact - old HH with 3-12m at BL and EL *
	eststo clear 
	
	foreach var in `vars' {
		xi: xtreg `var' i.treatment*i.time ch_agemo ch_sex, fe i(village_code) vce(cluster village_code)
		testparm _ItreXtim_1_1 _ItreXtim_2_1
		local pvalue=r(p)
		eststo `var'_1, addscalars(pvalue `pvalue')
	}
	
	#d; 
		xml_tab *_1, save($out/anthro_impact_3to12_samehh.xls) replace stats(N pvalue) b sd2 sheet(oldHH) 
		title("Anemia and anthropomentry of households with children 3-12 months of age at baseline and endline") 
		format(SCLR1 NCLR1) drop(_Itreatment_1 _Itreatment_2 _cons)
		font("Times New Roman" 12)
		note("Comparison is to a control group that did not receive any program services. All estimates controlled for child's age and sex, clustering, and attrition. All values are coefficient (SE).  *** p<0.01, ** p<0.05, * p<0.10");
	#d cr
	
*%%%%%%%%%%%%%%%%%%%%%%%*
*	ERASE TEMP FILES	*
*%%%%%%%%%%%%%%%%%%%%%%%*
	
	for any 1 2 3: erase "$do/roundX.dta" \ erase "$do/rXs18.dta" \ erase "$do/rXs18_health.dta" \ erase "$do/rXs24.dta" 
	for any hh children: erase "$do/X_new.dta" \ erase "$do/X.dta" 
exit 
